朋友圈自动同步

This commit is contained in:
wong
2025-04-11 16:15:48 +08:00
parent 2411bb6d05
commit 0cd689e6ae
20 changed files with 1862 additions and 207 deletions

View File

@@ -4,22 +4,55 @@ import { usePathname } from "next/navigation"
import BottomNav from "./BottomNav"
import { VideoTutorialButton } from "@/components/VideoTutorialButton"
import type React from "react"
import { createContext, useContext, useState, useEffect } from "react"
// 创建视图模式上下文
const ViewModeContext = createContext<{ viewMode: "desktop" | "mobile" }>({ viewMode: "desktop" })
// 创建视图模式钩子函数
export function useViewMode() {
const context = useContext(ViewModeContext)
if (!context) {
throw new Error("useViewMode must be used within a LayoutWrapper")
}
return context
}
export default function LayoutWrapper({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
const [viewMode, setViewMode] = useState<"desktop" | "mobile">("desktop")
// 检测视图模式
useEffect(() => {
const checkViewMode = () => {
setViewMode(window.innerWidth < 768 ? "mobile" : "desktop")
}
// 初始检测
checkViewMode()
// 监听窗口大小变化
window.addEventListener("resize", checkViewMode)
return () => {
window.removeEventListener("resize", checkViewMode)
}
}, [])
// 只在四个主页显示底部导航栏:首页、场景获客、工作台和我的
const mainPages = ["/", "/scenarios", "/workspace", "/profile"]
const showBottomNav = mainPages.includes(pathname)
return (
<div className="mx-auto w-full">
<main className="w-full mx-auto bg-white min-h-screen flex flex-col relative lg:max-w-7xl xl:max-w-[1200px]">
{children}
{showBottomNav && <BottomNav />}
{showBottomNav && <VideoTutorialButton />}
</main>
</div>
<ViewModeContext.Provider value={{ viewMode }}>
<div className="mx-auto w-full">
<main className="w-full mx-auto bg-white min-h-screen flex flex-col relative lg:max-w-7xl xl:max-w-[1200px]">
{children}
{showBottomNav && <BottomNav />}
{showBottomNav && <VideoTutorialButton />}
</main>
</div>
</ViewModeContext.Provider>
)
}

View File

@@ -0,0 +1,235 @@
"use client"
import { useState, useEffect } from "react"
import { useRouter } from "next/navigation"
import { ChevronLeft, Search } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { StepIndicator } from "../../components/step-indicator"
import { BasicSettings } from "../../components/basic-settings"
import { DeviceSelectionDialog } from "../../components/device-selection-dialog"
import { TagSelector } from "../../components/tag-selector"
import { api, ApiResponse } from "@/lib/api"
import { showToast } from "@/lib/toast"
interface TaskConfig {
id: number
workbenchId: number
interval: number
maxLikes: number
startTime: string
endTime: string
contentTypes: string[]
devices: number[]
targetGroups: string[]
tagOperator: number
createTime: string
updateTime: string
}
interface Task {
id: number
name: string
type: number
status: number
autoStart: number
createTime: string
updateTime: string
config: TaskConfig
}
export default function EditAutoLikePage({ params }: { params: { id: string } }) {
const router = useRouter()
const [currentStep, setCurrentStep] = useState(1)
const [deviceDialogOpen, setDeviceDialogOpen] = useState(false)
const [loading, setLoading] = useState(true)
const [formData, setFormData] = useState({
taskName: "",
likeInterval: 5,
maxLikesPerDay: 200,
timeRange: { start: "08:00", end: "22:00" },
contentTypes: ["text", "image", "video"],
enabled: true,
selectedDevices: [] as number[],
selectedTags: [] as string[],
tagOperator: "and" as "and" | "or",
})
useEffect(() => {
fetchTaskDetail()
}, [])
const fetchTaskDetail = async () => {
const loadingToast = showToast("正在加载任务信息...", "loading", true);
try {
const response = await api.get<{code: number, msg: string, data: Task}>(`/v1/workbench/detail?id=${params.id}`)
if (response.code === 200 && response.data) {
const task = response.data
setFormData({
taskName: task.name,
likeInterval: task.config.interval,
maxLikesPerDay: task.config.maxLikes,
timeRange: {
start: task.config.startTime,
end: task.config.endTime
},
contentTypes: task.config.contentTypes,
enabled: task.status === 1,
selectedDevices: task.config.devices,
selectedTags: task.config.targetGroups,
tagOperator: task.config.tagOperator === 1 ? "and" : "or"
})
} else {
showToast(response.msg || "获取任务信息失败", "error")
router.back()
}
} catch (error: any) {
console.error("获取任务详情失败:", error)
showToast(error?.message || "请检查网络连接", "error")
router.back()
} finally {
loadingToast.remove()
setLoading(false)
}
}
const handleUpdateFormData = (data: Partial<typeof formData>) => {
setFormData((prev) => ({ ...prev, ...data }))
}
const handleNext = () => {
setCurrentStep((prev) => Math.min(prev + 1, 3))
}
const handlePrev = () => {
setCurrentStep((prev) => Math.max(prev - 1, 1))
}
const handleComplete = async () => {
const loadingToast = showToast("正在更新任务...", "loading", true);
try {
const response = await api.post<ApiResponse>('/v1/workbench/update', {
id: params.id,
type: 1,
name: formData.taskName,
interval: formData.likeInterval,
maxLikes: formData.maxLikesPerDay,
startTime: formData.timeRange.start,
endTime: formData.timeRange.end,
contentTypes: formData.contentTypes,
enabled: formData.enabled,
devices: formData.selectedDevices,
targetGroups: formData.selectedTags,
tagOperator: formData.tagOperator === 'and' ? 1 : 2
});
if (response.code === 200) {
loadingToast.remove();
showToast(response.msg || "更新成功", "success");
router.push("/workspace/auto-like");
} else {
loadingToast.remove();
showToast(response.msg || "请稍后再试", "error");
}
} catch (error: any) {
console.error("更新自动点赞任务失败:", error);
loadingToast.remove();
showToast(error?.message || "请检查网络连接或稍后再试", "error");
}
};
if (loading) {
return null;
}
return (
<div className="min-h-screen bg-[#F8F9FA] pb-20">
<header className="sticky top-0 z-10 bg-white">
<div className="flex items-center h-14 px-4">
<Button variant="ghost" size="icon" onClick={() => router.back()} className="hover:bg-gray-50">
<ChevronLeft className="h-6 w-6" />
</Button>
<h1 className="ml-2 text-lg font-medium"></h1>
</div>
</header>
<div className="mt-8">
<StepIndicator currentStep={currentStep} />
<div className="mt-8">
{currentStep === 1 && (
<BasicSettings formData={formData} onChange={handleUpdateFormData} onNext={handleNext} />
)}
{currentStep === 2 && (
<div className="space-y-6 px-6">
<div className="relative">
<Search className="absolute left-3 top-4 h-5 w-5 text-gray-400" />
<Input
placeholder="选择设备"
className="h-12 pl-11 rounded-xl border-gray-200 text-base"
onClick={() => setDeviceDialogOpen(true)}
readOnly
value={formData.selectedDevices.length > 0 ? `已选择 ${formData.selectedDevices.length} 个设备` : ""}
/>
</div>
{formData.selectedDevices.length > 0 && (
<div className="text-base text-gray-500">{formData.selectedDevices.length} </div>
)}
<div className="flex space-x-4 pt-4">
<Button variant="outline" onClick={handlePrev} className="flex-1 h-12 rounded-xl text-base">
</Button>
<Button
onClick={handleNext}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
disabled={formData.selectedDevices.length === 0}
>
</Button>
</div>
<DeviceSelectionDialog
open={deviceDialogOpen}
onOpenChange={setDeviceDialogOpen}
selectedDevices={formData.selectedDevices}
onSelect={(devices) => {
handleUpdateFormData({ selectedDevices: devices })
setDeviceDialogOpen(false)
}}
/>
</div>
)}
{currentStep === 3 && (
<div className="px-6">
<TagSelector
selectedTags={formData.selectedTags}
tagOperator={formData.tagOperator}
onTagsChange={(tags) => handleUpdateFormData({ selectedTags: tags })}
onOperatorChange={(operator) => handleUpdateFormData({ tagOperator: operator })}
onBack={handlePrev}
onComplete={handleComplete}
/>
<div className="flex space-x-4 pt-4">
<Button variant="outline" onClick={handlePrev} className="flex-1 h-12 rounded-xl text-base">
</Button>
<Button
onClick={handleComplete}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
>
</Button>
</div>
</div>
)}
</div>
</div>
</div>
)
}

View File

@@ -294,7 +294,11 @@ export default function AutoLikePage() {
<div className="grid grid-cols-2 gap-4 mb-4">
<div className="text-sm text-gray-500">
<div>{task.config.devices.length} </div>
<div>{task.config.targetGroups.join(', ')}</div>
<div>{
task.config.targetGroups.length > 2
? `${task.config.targetGroups[0]}${task.config.targetGroups.length - 1}个标签`
: task.config.targetGroups.join(', ')
}</div>
</div>
<div className="text-sm text-gray-500">
<div>{task.config.interval} </div>

View File

@@ -1,33 +1,90 @@
"use client"
import { useState } from "react"
import { useState, useEffect } from "react"
import { useRouter } from "next/navigation"
import { ChevronLeft, Search } from "lucide-react"
import { Button } from "@/components/ui/button"
import { StepIndicator } from "../../components/step-indicator"
import { BasicSettings } from "../../components/basic-settings"
import { DeviceSelectionDialog } from "../../components/device-selection-dialog"
import { ContentLibrarySelectionDialog } from "../../components/content-library-selection-dialog"
import { Input } from "@/components/ui/input"
import { api, ApiResponse } from "@/lib/api"
import { showToast } from "@/lib/toast"
export default function EditMomentsSyncPage() {
// 定义基本设置表单数据类型与BasicSettings组件的formData类型匹配
interface BasicSettingsFormData {
taskName: string
startTime: string
endTime: string
syncCount: number
syncInterval: number
accountType: "business" | "personal"
enabled: boolean
}
export default function EditMomentsSyncPage({ params }: { params: { id: string } }) {
const router = useRouter()
const [currentStep, setCurrentStep] = useState(1)
const [deviceDialogOpen, setDeviceDialogOpen] = useState(false)
const [libraryDialogOpen, setLibraryDialogOpen] = useState(false)
const [isLoading, setIsLoading] = useState(true)
const [formData, setFormData] = useState({
taskName: "同步卡若主号",
taskName: "",
startTime: "06:00",
endTime: "23:59",
syncCount: 5,
accountType: "business" as const,
syncInterval: 30, // 同步间隔默认30分钟
accountType: "business" as "business" | "personal",
enabled: true,
selectedDevices: [] as string[],
selectedLibraries: [] as string[],
})
// 获取任务详情
useEffect(() => {
const fetchTaskDetail = async () => {
setIsLoading(true)
try {
const response = await api.get<ApiResponse>(`/v1/workbench/detail?id=${params.id}`)
if (response.code === 200 && response.data) {
const taskData = response.data
setFormData({
taskName: taskData.name || "",
startTime: taskData.startTime || "06:00",
endTime: taskData.endTime || "23:59",
syncCount: taskData.syncCount || 5,
syncInterval: taskData.syncInterval || 30,
accountType: taskData.syncType === 1 ? "business" : "personal",
enabled: !!taskData.enabled,
selectedDevices: taskData.devices || [],
selectedLibraries: taskData.contentLibraries || [],
})
} else {
showToast(response.msg || "获取任务详情失败", "error")
router.back()
}
} catch (error: any) {
console.error("获取任务详情失败:", error)
showToast(error?.message || "获取任务详情失败", "error")
router.back()
} finally {
setIsLoading(false)
}
}
fetchTaskDetail()
}, [params.id, router])
const handleUpdateFormData = (data: Partial<typeof formData>) => {
setFormData((prev) => ({ ...prev, ...data }))
}
// 专门用于基本设置的更新函数
const handleBasicSettingsUpdate = (data: Partial<BasicSettingsFormData>) => {
setFormData((prev) => ({ ...prev, ...data }))
}
const handleNext = () => {
setCurrentStep((prev) => Math.min(prev + 1, 3))
}
@@ -36,9 +93,44 @@ export default function EditMomentsSyncPage() {
setCurrentStep((prev) => Math.max(prev - 1, 1))
}
const handleComplete = () => {
console.log("Form submitted:", formData)
router.push("/workspace/moments-sync")
const handleComplete = async () => {
try {
const response = await api.post<ApiResponse>('/v1/workbench/update', {
id: params.id,
type: 2, // 朋友圈同步任务类型为2
name: formData.taskName,
syncInterval: formData.syncInterval,
syncCount: formData.syncCount,
syncType: formData.accountType === "business" ? 1 : 2, // 业务号为1人设号为2
startTime: formData.startTime,
endTime: formData.endTime,
accountType: formData.accountType === "business" ? 1 : 2,
status: formData.enabled ? 1 : 0, // 状态0=禁用1=启用
devices: formData.selectedDevices,
contentLibraries: formData.selectedLibraries
});
if (response.code === 200) {
showToast(response.msg || "更新成功", "success");
router.push("/workspace/moments-sync");
} else {
showToast(response.msg || "请稍后再试", "error");
}
} catch (error: any) {
console.error("更新朋友圈同步任务失败:", error);
showToast(error?.message || "请检查网络连接或稍后再试", "error");
}
};
if (isLoading) {
return (
<div className="min-h-screen bg-[#F8F9FA] flex justify-center items-center">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
<p className="text-gray-500">...</p>
</div>
</div>
)
}
return (
@@ -57,7 +149,19 @@ export default function EditMomentsSyncPage() {
<div className="mt-8">
{currentStep === 1 && (
<BasicSettings formData={formData} onChange={handleUpdateFormData} onNext={handleNext} />
<BasicSettings
formData={{
taskName: formData.taskName,
startTime: formData.startTime,
endTime: formData.endTime,
syncCount: formData.syncCount,
syncInterval: formData.syncInterval,
accountType: formData.accountType,
enabled: formData.enabled
}}
onChange={handleBasicSettingsUpdate}
onNext={handleNext}
/>
)}
{currentStep === 2 && (
@@ -69,6 +173,7 @@ export default function EditMomentsSyncPage() {
className="h-12 pl-11 rounded-xl border-gray-200 text-base"
onClick={() => setDeviceDialogOpen(true)}
readOnly
value={formData.selectedDevices.length > 0 ? `已选择 ${formData.selectedDevices.length} 个设备` : ""}
/>
</div>
@@ -83,6 +188,7 @@ export default function EditMomentsSyncPage() {
<Button
onClick={handleNext}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
disabled={formData.selectedDevices.length === 0}
>
</Button>
@@ -104,9 +210,19 @@ export default function EditMomentsSyncPage() {
<div className="space-y-6 px-6">
<div className="relative">
<Search className="absolute left-3 top-4 h-5 w-5 text-gray-400" />
<Input placeholder="选择内容库" className="h-12 pl-11 rounded-xl border-gray-200 text-base" />
<Input
placeholder="选择内容库"
className="h-12 pl-11 rounded-xl border-gray-200 text-base"
onClick={() => setLibraryDialogOpen(true)}
readOnly
value={formData.selectedLibraries.length > 0 ? `已选择 ${formData.selectedLibraries.length} 个内容库` : ""}
/>
</div>
{formData.selectedLibraries.length > 0 && (
<div className="text-base text-gray-500">{formData.selectedLibraries.length} </div>
)}
<div className="flex space-x-4 pt-4">
<Button variant="outline" onClick={handlePrev} className="flex-1 h-12 rounded-xl text-base">
@@ -114,10 +230,21 @@ export default function EditMomentsSyncPage() {
<Button
onClick={handleComplete}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
disabled={formData.selectedLibraries.length === 0}
>
</Button>
</div>
<ContentLibrarySelectionDialog
open={libraryDialogOpen}
onOpenChange={setLibraryDialogOpen}
selectedLibraries={formData.selectedLibraries}
onSelect={(libraries) => {
handleUpdateFormData({ selectedLibraries: libraries })
setLibraryDialogOpen(false)
}}
/>
</div>
)}
</div>

View File

@@ -2,52 +2,216 @@
import { useState, useEffect } from "react"
import { useRouter } from "next/navigation"
import { ChevronLeft } from "lucide-react"
import { ChevronLeft, MoreVertical, Clock, Edit, Trash2, Copy, RefreshCw, FileText, MessageSquare, History } from "lucide-react"
import { Card } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Avatar } from "@/components/ui/avatar"
import { Switch } from "@/components/ui/switch"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"
import { api, ApiResponse } from "@/lib/api"
import { showToast } from "@/lib/toast"
interface SyncTask {
// 定义任务详情的接口
interface TaskDetail {
id: string
name: string
status: "running" | "paused"
deviceCount: number
contentLib: string
syncType: number
accountType: number
syncCount: number
syncInterval: number
startTime: string
endTime: string
enabled: boolean
devices: {
id: string
name: string
avatar: string
}[]
contentLibraries: {
id: string
name: string
count: number
}[]
lastSyncTime: string
createTime: string
creator: string
}
export default function ViewMomentsSyncTask({ params }: { params: { id: string } }) {
// 定义同步历史的接口
interface SyncHistory {
id: string
syncTime: string
content: string
contentType: "text" | "image" | "video"
status: "success" | "failed"
errorMessage?: string
}
export default function MomentsSyncDetailPage({ params }: { params: { id: string } }) {
const router = useRouter()
const [task, setTask] = useState<SyncTask | null>(null)
const [taskDetail, setTaskDetail] = useState<TaskDetail | null>(null)
const [syncHistory, setSyncHistory] = useState<SyncHistory[]>([])
const [isLoading, setIsLoading] = useState(true)
const [activeTab, setActiveTab] = useState("overview")
const [showDeleteAlert, setShowDeleteAlert] = useState(false)
// 获取任务详情
useEffect(() => {
// Fetch task data from API
// For now, we'll use mock data
setTask({
id: params.id,
name: "同步卡若主号",
deviceCount: 2,
contentLib: "卡若朋友圈",
syncCount: 307,
lastSyncTime: "2025-02-06 13:12:35",
createTime: "2024-11-20 19:04:14",
creator: "karuo",
status: "running",
})
}, [params.id])
const fetchTaskDetail = async () => {
setIsLoading(true)
try {
const response = await api.get<ApiResponse>(`/v1/workbench/detail?id=${params.id}`)
if (response.code === 200 && response.data) {
setTaskDetail(response.data)
// 获取同步历史
if (activeTab === "history") {
fetchSyncHistory()
}
} else {
showToast(response.msg || "获取任务详情失败", "error")
router.push("/workspace/moments-sync")
}
} catch (error: any) {
console.error("获取任务详情失败:", error)
showToast(error?.message || "获取任务详情失败", "error")
router.push("/workspace/moments-sync")
} finally {
setIsLoading(false)
}
}
const toggleTaskStatus = () => {
if (task) {
setTask({ ...task, status: task.status === "running" ? "paused" : "running" })
fetchTaskDetail()
}, [params.id, router])
// 获取同步历史
const fetchSyncHistory = async () => {
try {
const response = await api.get<ApiResponse>(`/v1/workbench/sync/history?id=${params.id}`)
if (response.code === 200 && response.data) {
setSyncHistory(response.data.list || [])
} else {
setSyncHistory([])
}
} catch (error) {
console.error("获取同步历史失败:", error)
setSyncHistory([])
}
}
if (!task) {
return <div>Loading...</div>
// 切换Tab时加载数据
const handleTabChange = (value: string) => {
setActiveTab(value)
if (value === "history" && syncHistory.length === 0) {
fetchSyncHistory()
}
}
// 切换任务状态
const toggleTaskStatus = async () => {
if (!taskDetail) return
try {
const newStatus = taskDetail.status === "running" ? "paused" : "running"
const response = await api.post<ApiResponse>('/v1/workbench/update/status', {
id: params.id,
status: newStatus === "running" ? 1 : 0
})
if (response.code === 200) {
setTaskDetail({
...taskDetail,
status: newStatus
})
showToast(`任务已${newStatus === "running" ? "启用" : "暂停"}`, "success")
} else {
showToast(response.msg || "操作失败", "error")
}
} catch (error: any) {
console.error("更新任务状态失败:", error)
showToast(error?.message || "更新任务状态失败", "error")
}
}
// 编辑任务
const handleEdit = () => {
router.push(`/workspace/moments-sync/${params.id}/edit`)
}
// 确认删除
const confirmDelete = () => {
setShowDeleteAlert(true)
}
// 执行删除
const handleDelete = async () => {
try {
const response = await api.post<ApiResponse>('/v1/workbench/delete', {
id: params.id
})
if (response.code === 200) {
showToast("删除成功", "success")
router.push("/workspace/moments-sync")
} else {
showToast(response.msg || "删除失败", "error")
}
} catch (error: any) {
console.error("删除任务失败:", error)
showToast(error?.message || "删除任务失败", "error")
} finally {
setShowDeleteAlert(false)
}
}
// 复制任务
const handleCopy = async () => {
try {
const response = await api.post<ApiResponse>('/v1/workbench/copy', {
id: params.id
})
if (response.code === 200) {
showToast("复制成功,正在跳转到新任务", "success")
// 假设后端返回了新任务的ID
if (response.data?.id) {
router.push(`/workspace/moments-sync/${response.data.id}`)
} else {
router.push("/workspace/moments-sync")
}
} else {
showToast(response.msg || "复制失败", "error")
}
} catch (error: any) {
console.error("复制任务失败:", error)
showToast(error?.message || "复制任务失败", "error")
}
}
if (isLoading) {
return (
<div className="min-h-screen bg-[#F8F9FA] flex justify-center items-center">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
<p className="text-gray-500">...</p>
</div>
</div>
)
}
if (!taskDetail) {
return (
<div className="min-h-screen bg-[#F8F9FA] flex justify-center items-center">
<div className="text-center">
<p className="text-gray-500 mb-4"></p>
<Button onClick={() => router.push("/workspace/moments-sync")}></Button>
</div>
</div>
)
}
return (
@@ -55,53 +219,192 @@ export default function ViewMomentsSyncTask({ params }: { params: { id: string }
<header className="sticky top-0 z-10 bg-white border-b">
<div className="flex items-center justify-between p-4">
<div className="flex items-center space-x-3">
<Button variant="ghost" size="icon" onClick={() => router.back()}>
<Button variant="ghost" size="icon" onClick={() => router.push("/workspace/moments-sync")}>
<ChevronLeft className="h-5 w-5" />
</Button>
<h1 className="text-lg font-medium"></h1>
<h1 className="text-lg font-medium"></h1>
</div>
<div className="flex items-center space-x-2">
<Switch
checked={taskDetail.status === "running"}
onCheckedChange={toggleTaskStatus}
/>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon">
<MoreVertical className="h-5 w-5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={handleEdit}>
<Edit className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={handleCopy}>
<Copy className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={confirmDelete} className="text-red-500 hover:text-red-600">
<Trash2 className="h-4 w-4 mr-2" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
<Button onClick={() => router.push(`/workspace/moments-sync/${task.id}/edit`)}></Button>
</div>
</header>
<div className="p-4">
<Card className="p-6">
<div className="flex items-center justify-between mb-6">
<div className="flex items-center space-x-2">
<h2 className="text-2xl font-bold">{task.name}</h2>
<Badge variant={task.status === "running" ? "success" : "secondary"}>
{task.status === "running" ? "进行中" : "已暂停"}
</Badge>
</div>
<Switch checked={task.status === "running"} onCheckedChange={toggleTaskStatus} />
</div>
<div className="grid grid-cols-2 gap-6 mb-6">
<div>
<h3 className="text-lg font-semibold mb-2"></h3>
<div className="space-y-2">
<p>{task.deviceCount} </p>
<p>{task.contentLib}</p>
<p>{task.syncCount} </p>
<p>{task.creator}</p>
<Card className="mb-4">
<div className="p-4 border-b">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-2">
<h2 className="text-xl font-semibold">{taskDetail.name}</h2>
<Badge variant={taskDetail.status === "running" ? "success" : "secondary"}>
{taskDetail.status === "running" ? "进行中" : "已暂停"}
</Badge>
</div>
</div>
<div>
<h3 className="text-lg font-semibold mb-2"></h3>
<div className="space-y-2">
<p>{task.createTime}</p>
<p>{task.lastSyncTime}</p>
</div>
<div className="grid grid-cols-2 gap-4 text-sm text-gray-500">
<div>{taskDetail.createTime}</div>
<div>{taskDetail.creator}</div>
<div>{taskDetail.lastSyncTime}</div>
<div>{taskDetail.syncCount} </div>
</div>
</div>
<div className="border-t pt-4">
<h3 className="text-lg font-semibold mb-2"></h3>
{/* Add content preview here */}
<p className="text-gray-500"></p>
</div>
</Card>
<Tabs value={activeTab} onValueChange={handleTabChange} className="mb-4">
<TabsList className="grid grid-cols-3">
<TabsTrigger value="overview"></TabsTrigger>
<TabsTrigger value="devices"></TabsTrigger>
<TabsTrigger value="history"></TabsTrigger>
</TabsList>
<TabsContent value="overview" className="mt-4">
<Card className="p-4">
<div className="space-y-4">
<div>
<div className="font-medium mb-1"></div>
<div className="text-gray-600">{taskDetail.accountType === 1 ? "业务号" : "人设号"}</div>
</div>
<div>
<div className="font-medium mb-1"></div>
<div className="text-gray-600">{taskDetail.syncType === 1 ? "循环同步" : "实时更新"}</div>
</div>
<div>
<div className="font-medium mb-1"></div>
<div className="text-gray-600">{taskDetail.syncInterval} </div>
</div>
<div>
<div className="font-medium mb-1"></div>
<div className="text-gray-600">{taskDetail.syncCount} </div>
</div>
<div>
<div className="font-medium mb-1"></div>
<div className="text-gray-600">{taskDetail.startTime} - {taskDetail.endTime}</div>
</div>
<div>
<div className="font-medium mb-1"></div>
<div className="flex flex-wrap gap-2 mt-1">
{taskDetail.contentLibraries.map((lib) => (
<Badge key={lib.id} variant="outline" className="bg-blue-50">
{lib.name}
</Badge>
))}
</div>
</div>
</div>
</Card>
</TabsContent>
<TabsContent value="devices" className="mt-4">
<Card className="p-4">
{taskDetail.devices.length === 0 ? (
<div className="text-center py-8 text-gray-500"></div>
) : (
<div className="divide-y">
{taskDetail.devices.map((device) => (
<div key={device.id} className="flex items-center py-3 first:pt-0 last:pb-0">
<Avatar className="h-10 w-10 mr-3">
{device.avatar ? (
<img src={device.avatar} alt={device.name} />
) : (
<div className="bg-blue-100 text-blue-600 h-full w-full flex items-center justify-center">
{device.name.charAt(0)}
</div>
)}
</Avatar>
<div>
<div className="font-medium">{device.name}</div>
<div className="text-xs text-gray-500">ID: {device.id}</div>
</div>
</div>
))}
</div>
)}
</Card>
</TabsContent>
<TabsContent value="history" className="mt-4">
<Card className="p-4">
<div className="flex items-center justify-between mb-4">
<h3 className="font-medium"></h3>
<Button variant="outline" size="sm" onClick={fetchSyncHistory}>
<RefreshCw className="h-4 w-4 mr-2" />
</Button>
</div>
{syncHistory.length === 0 ? (
<div className="text-center py-8 text-gray-500"></div>
) : (
<div className="space-y-4">
{syncHistory.map((record) => (
<div key={record.id} className="border rounded-lg p-3">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center">
{record.contentType === "text" && <FileText className="h-4 w-4 mr-2 text-gray-500" />}
{record.contentType === "image" && <img className="h-4 w-4 mr-2" src="/icons/image.svg" alt="图片" />}
{record.contentType === "video" && <img className="h-4 w-4 mr-2" src="/icons/video.svg" alt="视频" />}
<Badge variant={record.status === "success" ? "success" : "destructive"} className="text-xs">
{record.status === "success" ? "成功" : "失败"}
</Badge>
</div>
<div className="text-xs text-gray-500">{record.syncTime}</div>
</div>
<div className="text-sm text-gray-700 line-clamp-2">{record.content}</div>
{record.status === "failed" && record.errorMessage && (
<div className="mt-2 text-xs text-red-500">
: {record.errorMessage}
</div>
)}
</div>
))}
</div>
)}
</Card>
</TabsContent>
</Tabs>
</div>
{/* 删除确认对话框 */}
<AlertDialog open={showDeleteAlert} onOpenChange={setShowDeleteAlert}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="bg-red-500 hover:bg-red-600">
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}

View File

@@ -13,6 +13,7 @@ interface BasicSettingsProps {
startTime: string
endTime: string
syncCount: number
syncInterval: number
accountType: "business" | "personal"
enabled: boolean
}
@@ -85,6 +86,30 @@ export function BasicSettings({ formData, onChange, onNext }: BasicSettingsProps
</div>
</div>
<div>
<div className="text-base font-medium mb-2"></div>
<div className="flex items-center space-x-5">
<Button
variant="outline"
size="lg"
onClick={() => onChange({ syncInterval: Math.max(10, formData.syncInterval - 10) })}
className="h-12 w-12 rounded-xl bg-white border-gray-200"
>
<Minus className="h-5 w-5" />
</Button>
<span className="w-8 text-center text-lg font-medium">{formData.syncInterval}</span>
<Button
variant="outline"
size="lg"
onClick={() => onChange({ syncInterval: Math.min(120, formData.syncInterval + 10) })}
className="h-12 w-12 rounded-xl bg-white border-gray-200"
>
<Plus className="h-5 w-5" />
</Button>
<span className="text-gray-500"></span>
</div>
</div>
<div>
<div className="text-base font-medium mb-2"></div>
<div className="flex space-x-4">

View File

@@ -0,0 +1,114 @@
"use client"
import { useState } from "react"
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { Input } from "@/components/ui/input"
import { Button } from "@/components/ui/button"
import { Search, CheckCircle2, Circle } from "lucide-react"
import { ScrollArea } from "@/components/ui/scroll-area"
interface ContentLibrarySelectionDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
selectedLibraries: string[]
onSelect: (libraries: string[]) => void
}
export function ContentLibrarySelectionDialog({
open,
onOpenChange,
selectedLibraries,
onSelect,
}: ContentLibrarySelectionDialogProps) {
const [searchQuery, setSearchQuery] = useState("")
const [libraries] = useState([
{ id: "1", name: "卡若朋友圈", count: 58 },
{ id: "2", name: "暗黑4代练", count: 422 },
{ id: "3", name: "家装设计", count: 107 },
{ id: "4", name: "美食分享", count: 321 },
{ id: "5", name: "旅游攻略", count: 89 },
])
const [tempSelectedLibraries, setTempSelectedLibraries] = useState<string[]>(selectedLibraries)
const toggleLibrary = (libraryId: string) => {
setTempSelectedLibraries((prev) =>
prev.includes(libraryId) ? prev.filter((id) => id !== libraryId) : [...prev, libraryId]
)
}
const handleConfirm = () => {
onSelect(tempSelectedLibraries)
onOpenChange(false)
}
const handleCancel = () => {
setTempSelectedLibraries(selectedLibraries)
onOpenChange(false)
}
const filteredLibraries = libraries.filter((library) =>
library.name.toLowerCase().includes(searchQuery.toLowerCase())
)
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md p-0 overflow-hidden">
<DialogHeader className="px-4 py-3 border-b">
<DialogTitle></DialogTitle>
</DialogHeader>
<div className="p-4">
<div className="relative mb-4">
<Search className="absolute left-3 top-2.5 h-5 w-5 text-gray-400" />
<Input
placeholder="搜索内容库"
className="pl-10"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
/>
</div>
<ScrollArea className="h-[300px] pr-4">
<div className="space-y-2">
{filteredLibraries.map((library) => (
<div
key={library.id}
className="flex items-center justify-between p-3 rounded-lg border hover:bg-gray-50 cursor-pointer"
onClick={() => toggleLibrary(library.id)}
>
<div>
<h3 className="font-medium">{library.name}</h3>
<p className="text-sm text-gray-500">{library.count}</p>
</div>
{tempSelectedLibraries.includes(library.id) ? (
<CheckCircle2 className="h-6 w-6 text-blue-500" />
) : (
<Circle className="h-6 w-6 text-gray-300" />
)}
</div>
))}
</div>
</ScrollArea>
</div>
<div className="flex border-t p-4">
<Button
variant="outline"
className="flex-1 mr-2"
onClick={handleCancel}
>
</Button>
<Button
className="flex-1"
onClick={handleConfirm}
disabled={tempSelectedLibraries.length === 0}
>
({tempSelectedLibraries.length})
</Button>
</div>
</DialogContent>
</Dialog>
)
}

View File

@@ -7,19 +7,34 @@ import { Button } from "@/components/ui/button"
import { StepIndicator } from "../components/step-indicator"
import { BasicSettings } from "../components/basic-settings"
import { DeviceSelectionDialog } from "../components/device-selection-dialog"
import { ContentLibrarySelectionDialog } from "../components/content-library-selection-dialog"
import { Input } from "@/components/ui/input"
import { toast } from "@/components/ui/use-toast"
import { api, ApiResponse } from "@/lib/api"
import { showToast } from "@/lib/toast"
// 定义基本设置表单数据类型与BasicSettings组件的formData类型匹配
interface BasicSettingsFormData {
taskName: string
startTime: string
endTime: string
syncCount: number
syncInterval: number
accountType: "business" | "personal"
enabled: boolean
}
export default function NewMomentsSyncPage() {
const router = useRouter()
const [currentStep, setCurrentStep] = useState(1)
const [deviceDialogOpen, setDeviceDialogOpen] = useState(false)
const [libraryDialogOpen, setLibraryDialogOpen] = useState(false)
const [formData, setFormData] = useState({
taskName: "",
startTime: "06:00",
endTime: "23:59",
syncCount: 5,
accountType: "business" as const,
syncInterval: 30, // 同步间隔默认30分钟
accountType: "business" as "business" | "personal",
enabled: true,
selectedDevices: [] as string[],
selectedLibraries: [] as string[],
@@ -29,6 +44,11 @@ export default function NewMomentsSyncPage() {
setFormData((prev) => ({ ...prev, ...data }))
}
// 专门用于基本设置的更新函数
const handleBasicSettingsUpdate = (data: Partial<BasicSettingsFormData>) => {
setFormData((prev) => ({ ...prev, ...data }))
}
const handleNext = () => {
setCurrentStep((prev) => Math.min(prev + 1, 3))
}
@@ -38,13 +58,31 @@ export default function NewMomentsSyncPage() {
}
const handleComplete = async () => {
console.log("Form submitted:", formData)
await new Promise((resolve) => setTimeout(resolve, 1000))
toast({
title: "创建成<E5BBBA><E68890><EFBFBD>",
description: "朋友圈同步任务已创建并开始执行",
})
router.push("/workspace/moments-sync")
try {
const response = await api.post<ApiResponse>('/v1/workbench/create', {
type: 2, // 朋友圈同步任务类型为2
name: formData.taskName,
syncInterval: formData.syncInterval,
syncCount: formData.syncCount,
syncType: formData.accountType === "business" ? 1 : 2, // 业务号为1人设号为2
startTime: formData.startTime,
endTime: formData.endTime,
accountType: formData.accountType === "business" ? 1 : 2,
status: formData.enabled ? 1 : 0, // 状态0=禁用1=启用
devices: formData.selectedDevices,
contentLibraries: formData.selectedLibraries
});
if (response.code === 200) {
showToast(response.msg || "创建成功", "success");
router.push("/workspace/moments-sync");
} else {
showToast(response.msg || "请稍后再试", "error");
}
} catch (error: any) {
console.error("创建朋友圈同步任务失败:", error);
showToast(error?.message || "请检查网络连接或稍后再试", "error");
}
}
return (
@@ -63,7 +101,19 @@ export default function NewMomentsSyncPage() {
<div className="mt-8">
{currentStep === 1 && (
<BasicSettings formData={formData} onChange={handleUpdateFormData} onNext={handleNext} />
<BasicSettings
formData={{
taskName: formData.taskName,
startTime: formData.startTime,
endTime: formData.endTime,
syncCount: formData.syncCount,
syncInterval: formData.syncInterval,
accountType: formData.accountType,
enabled: formData.enabled
}}
onChange={handleBasicSettingsUpdate}
onNext={handleNext}
/>
)}
{currentStep === 2 && (
@@ -75,6 +125,7 @@ export default function NewMomentsSyncPage() {
className="h-12 pl-11 rounded-xl border-gray-200 text-base"
onClick={() => setDeviceDialogOpen(true)}
readOnly
value={formData.selectedDevices.length > 0 ? `已选择 ${formData.selectedDevices.length} 个设备` : ""}
/>
</div>
@@ -89,6 +140,7 @@ export default function NewMomentsSyncPage() {
<Button
onClick={handleNext}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
disabled={formData.selectedDevices.length === 0}
>
</Button>
@@ -110,9 +162,19 @@ export default function NewMomentsSyncPage() {
<div className="space-y-6 px-6">
<div className="relative">
<Search className="absolute left-3 top-4 h-5 w-5 text-gray-400" />
<Input placeholder="选择内容库" className="h-12 pl-11 rounded-xl border-gray-200 text-base" />
<Input
placeholder="选择内容库"
className="h-12 pl-11 rounded-xl border-gray-200 text-base"
onClick={() => setLibraryDialogOpen(true)}
readOnly
value={formData.selectedLibraries.length > 0 ? `已选择 ${formData.selectedLibraries.length} 个内容库` : ""}
/>
</div>
{formData.selectedLibraries.length > 0 && (
<div className="text-base text-gray-500">{formData.selectedLibraries.length} </div>
)}
<div className="flex space-x-4 pt-4">
<Button variant="outline" onClick={handlePrev} className="flex-1 h-12 rounded-xl text-base">
@@ -120,10 +182,21 @@ export default function NewMomentsSyncPage() {
<Button
onClick={handleComplete}
className="flex-1 h-12 bg-blue-600 hover:bg-blue-700 rounded-xl text-base shadow-sm"
disabled={formData.selectedLibraries.length === 0}
>
</Button>
</div>
<ContentLibrarySelectionDialog
open={libraryDialogOpen}
onOpenChange={setLibraryDialogOpen}
selectedLibraries={formData.selectedLibraries}
onSelect={(libraries) => {
handleUpdateFormData({ selectedLibraries: libraries })
setLibraryDialogOpen(false)
}}
/>
</div>
)}
</div>

View File

@@ -1,7 +1,7 @@
"use client"
import { useState } from "react"
import { ChevronLeft, Plus, Filter, Search, RefreshCw, MoreVertical, Clock, Edit, Trash2, Eye } from "lucide-react"
import { useState, useEffect } from "react"
import { ChevronLeft, Plus, Filter, Search, RefreshCw, MoreVertical, Clock, Edit, Trash2, Eye, Copy } from "lucide-react"
import { Card } from "@/components/ui/card"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
@@ -10,6 +10,18 @@ import { Badge } from "@/components/ui/badge"
import { useRouter } from "next/navigation"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
import { Switch } from "@/components/ui/switch"
import { api, ApiResponse } from "@/lib/api"
import { showToast } from "@/lib/toast"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle
} from "@/components/ui/alert-dialog"
interface SyncTask {
id: string
@@ -21,55 +33,146 @@ interface SyncTask {
lastSyncTime: string
createTime: string
creator: string
libraries?: string[]
}
export default function MomentsSyncPage() {
const router = useRouter()
const [tasks, setTasks] = useState<SyncTask[]>([
{
id: "1",
name: "同步卡若主号",
deviceCount: 2,
contentLib: "卡若朋友圈",
syncCount: 307,
lastSyncTime: "2025-02-06 13:12:35",
createTime: "2024-11-20 19:04:14",
creator: "karuo",
status: "running",
},
{
id: "2",
name: "暗黑4业务",
deviceCount: 1,
contentLib: "暗黑4代练",
syncCount: 622,
lastSyncTime: "2024-03-04 14:09:35",
createTime: "2024-03-04 14:29:04",
creator: "lkdie",
status: "paused",
},
])
const [tasks, setTasks] = useState<SyncTask[]>([])
const [isLoading, setIsLoading] = useState(true)
const [searchQuery, setSearchQuery] = useState("")
const [showDeleteAlert, setShowDeleteAlert] = useState(false)
const [taskToDelete, setTaskToDelete] = useState<string | null>(null)
const handleDelete = (taskId: string) => {
setTasks(tasks.filter((task) => task.id !== taskId))
// 获取任务列表
const fetchTasks = async () => {
const loadingToast = showToast("正在加载任务列表...", "loading", true);
setIsLoading(true)
try {
const response = await api.get<ApiResponse>('/v1/workbench/list?type=2')
if (response.code === 200 && response.data) {
setTasks(response.data.list || [])
} else {
showToast(response.msg || "获取任务列表失败", "error")
}
} catch (error: any) {
console.error("获取朋友圈同步任务列表失败:", error)
showToast(error?.message || "请检查网络连接", "error")
} finally {
loadingToast.remove();
setIsLoading(false)
}
}
// 组件加载时获取任务列表
useEffect(() => {
fetchTasks()
}, [])
// 搜索任务
const handleSearch = () => {
fetchTasks()
}
// 切换任务状态
const toggleTaskStatus = async (taskId: string, currentStatus: "running" | "paused") => {
const loadingToast = showToast("正在更新任务状态...", "loading", true);
try {
const newStatus = currentStatus === "running" ? "paused" : "running"
const response = await api.post<ApiResponse>('/v1/workbench/update-status', {
id: taskId,
status: newStatus === "running" ? 1 : 0
})
if (response.code === 200) {
setTasks(
tasks.map((task) =>
task.id === taskId ? { ...task, status: newStatus } : task
)
)
loadingToast.remove();
showToast(`任务已${newStatus === "running" ? "启用" : "暂停"}`, "success")
} else {
loadingToast.remove();
showToast(response.msg || "操作失败", "error")
}
} catch (error: any) {
console.error("更新任务状态失败:", error)
loadingToast.remove();
showToast(error?.message || "更新任务状态失败", "error")
}
}
// 确认删除
const confirmDelete = (taskId: string) => {
setTaskToDelete(taskId)
setShowDeleteAlert(true)
}
// 执行删除
const handleDelete = async () => {
if (!taskToDelete) return
const loadingToast = showToast("正在删除任务...", "loading", true);
try {
const response = await api.delete<ApiResponse>(`/v1/workbench/delete?id=${taskToDelete}`)
if (response.code === 200) {
setTasks(tasks.filter((task) => task.id !== taskToDelete))
loadingToast.remove();
showToast("删除成功", "success")
} else {
loadingToast.remove();
showToast(response.msg || "删除失败", "error")
}
} catch (error: any) {
console.error("删除任务失败:", error)
loadingToast.remove();
showToast(error?.message || "删除任务失败", "error")
} finally {
setTaskToDelete(null)
setShowDeleteAlert(false)
}
}
// 编辑任务
const handleEdit = (taskId: string) => {
router.push(`/workspace/moments-sync/${taskId}/edit`)
}
// 查看任务详情
const handleView = (taskId: string) => {
router.push(`/workspace/moments-sync/${taskId}`)
}
const toggleTaskStatus = (taskId: string) => {
setTasks(
tasks.map((task) =>
task.id === taskId ? { ...task, status: task.status === "running" ? "paused" : "running" } : task,
),
)
// 复制任务
const handleCopy = async (taskId: string) => {
const loadingToast = showToast("正在复制任务...", "loading", true);
try {
const response = await api.post<ApiResponse>('/v1/workbench/copy', {
id: taskId
})
if (response.code === 200) {
loadingToast.remove();
showToast("复制成功", "success")
fetchTasks() // 重新获取列表
} else {
loadingToast.remove();
showToast(response.msg || "复制失败", "error")
}
} catch (error: any) {
console.error("复制任务失败:", error)
loadingToast.remove();
showToast(error?.message || "复制任务失败", "error")
}
}
// 过滤任务
const filteredTasks = tasks.filter(
(task) => task.name.toLowerCase().includes(searchQuery.toLowerCase())
)
return (
<div className="flex-1 bg-gray-50 min-h-screen">
<header className="sticky top-0 z-10 bg-white border-b">
@@ -94,75 +197,132 @@ export default function MomentsSyncPage() {
<div className="flex items-center space-x-2">
<div className="relative flex-1">
<Search className="absolute left-3 top-2.5 h-4 w-4 text-gray-400" />
<Input placeholder="搜索任务名称" className="pl-9" />
<Input
placeholder="搜索任务名称"
className="pl-9"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
/>
</div>
<Button variant="outline" size="icon">
<Button variant="outline" size="icon" onClick={handleSearch}>
<Filter className="h-4 w-4" />
</Button>
<Button variant="outline" size="icon">
<RefreshCw className="h-4 w-4" />
<Button
variant="outline"
size="icon"
onClick={fetchTasks}
disabled={isLoading}
>
<RefreshCw className={`h-4 w-4 ${isLoading ? 'animate-spin' : ''}`} />
</Button>
</div>
</Card>
<div className="space-y-4">
{tasks.map((task) => (
<Card key={task.id} className="p-4">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-2">
<h3 className="font-medium">{task.name}</h3>
<Badge variant={task.status === "running" ? "success" : "secondary"}>
{task.status === "running" ? "进行中" : "已暂停"}
</Badge>
{isLoading ? (
<div className="flex justify-center items-center py-12">
<div className="flex flex-col items-center">
<RefreshCw className="h-8 w-8 text-blue-500 animate-spin mb-4" />
<p className="text-gray-500">...</p>
</div>
</div>
) : filteredTasks.length === 0 ? (
<div className="flex justify-center items-center py-12">
<div className="flex flex-col items-center">
<p className="text-gray-500 mb-4"></p>
<Link href="/workspace/moments-sync/new">
<Button size="sm">
<Plus className="h-4 w-4 mr-2" />
</Button>
</Link>
</div>
</div>
) : (
<div className="space-y-4">
{filteredTasks.map((task) => (
<Card key={task.id} className="p-4">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-2">
<h3 className="font-medium">{task.name}</h3>
<Badge variant={task.status === 1 ? "success" : "secondary"}>
{task.status === "running" ? "进行中" : "已暂停"}
</Badge>
</div>
<div className="flex items-center space-x-2">
<Switch
checked={task.status === 1}
onCheckedChange={() => toggleTaskStatus(task.id, task.status)}
/>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm">
<MoreVertical className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem onClick={() => handleView(task.id)}>
<Eye className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleEdit(task.id)}>
<Edit className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleCopy(task.id)}>
<Copy className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => confirmDelete(task.id)}>
<Trash2 className="h-4 w-4 mr-2" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="flex items-center space-x-2">
<Switch checked={task.status === "running"} onCheckedChange={() => toggleTaskStatus(task.id)} />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm">
<MoreVertical className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem onClick={() => handleView(task.id)}>
<Eye className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleEdit(task.id)}>
<Edit className="h-4 w-4 mr-2" />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleDelete(task.id)}>
<Trash2 className="h-4 w-4 mr-2" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="grid grid-cols-2 gap-4 mb-4">
<div className="text-sm text-gray-500">
<div>{task.deviceCount} </div>
<div>{task.contentLib}</div>
<div className="grid grid-cols-2 gap-4 mb-4">
<div className="text-sm text-gray-500">
<div>{task.deviceCount} </div>
<div>{task.contentLib}</div>
</div>
<div className="text-sm text-gray-500">
<div>{task.syncCount} </div>
<div>{task.creator}</div>
</div>
</div>
<div className="text-sm text-gray-500">
<div>{task.syncCount} </div>
<div>{task.creator}</div>
</div>
</div>
<div className="flex items-center justify-between text-xs text-gray-500 border-t pt-4">
<div className="flex items-center">
<Clock className="w-4 h-4 mr-1" />
{task.lastSyncTime}
<div className="flex items-center justify-between text-xs text-gray-500 border-t pt-4">
<div className="flex items-center">
<Clock className="w-4 h-4 mr-1" />
{task.lastSyncTime}
</div>
<div>{task.createTime}</div>
</div>
<div>{task.createTime}</div>
</div>
</Card>
))}
</div>
</Card>
))}
</div>
)}
</div>
{/* 删除确认对话框 */}
<AlertDialog open={showDeleteAlert} onOpenChange={setShowDeleteAlert}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="bg-red-500 hover:bg-red-600">
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}

View File

@@ -12,6 +12,7 @@ const badgeVariants = cva(
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive: "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
outline: "text-foreground",
success: "border-transparent bg-green-500 text-white shadow hover:bg-green-600",
},
},
defaultVariants: {

View File

@@ -115,7 +115,7 @@ class WechatFriendController extends BaseController
'additionalPicture' => $item['additionalPicture'],
'desc' => $item['desc'],
'country' => $item['country'],
'province' => isset($item['province']) ? $item['province'] : '',
'privince' => isset($item['privince']) ? $item['privince'] : '',
'city' => isset($item['city']) ? $item['city'] : '',
'createTime' =>isset($item['createTime']) ? $item['createTime'] : '',
'updateTime' => time()

View File

@@ -8,6 +8,7 @@ use think\console\Output;
use think\facade\Log;
use think\Queue;
use app\job\WechatFriendJob;
use think\facade\Cache;
class WechatFriendCommand extends Command
{
@@ -22,12 +23,16 @@ class WechatFriendCommand extends Command
$output->writeln('开始处理微信列表任务...');
try {
// 初始页码
$pageIndex = 0;
// 从缓存获取初始页码和上次处理的好友ID缓存10分钟有效
$pageIndex = Cache::get('friendsPage', 0);
$preFriendId = Cache::get('preFriendId', '');
$output->writeln('从缓存获取页码:' . $pageIndex . '上次处理的好友ID' . ($preFriendId ?: '无'));
$pageSize = 1000; // 每页获取1000条记录
// 将第一页任务添加到队列
$this->addToQueue($pageIndex, $pageSize);
// 将任务添加到队列
$this->addToQueue($pageIndex, $pageSize, $preFriendId);
$output->writeln('微信列表任务已添加到队列');
} catch (\Exception $e) {
@@ -43,12 +48,14 @@ class WechatFriendCommand extends Command
* 添加任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
* @param string $preFriendId 上一个好友ID
*/
protected function addToQueue($pageIndex, $pageSize)
protected function addToQueue($pageIndex, $pageSize, $preFriendId = '')
{
$data = [
'pageIndex' => $pageIndex,
'pageSize' => $pageSize
'pageSize' => $pageSize,
'preFriendId' => $preFriendId
];
// 添加到队列,设置任务名为 wechat_friends

View File

@@ -54,5 +54,7 @@ Route::group('v1/', function () {
Route::post('update-status', 'app\\cunkebao\\controller\\WorkbenchController@updateStatus'); // 更新工作台状态
Route::delete('delete', 'app\\cunkebao\\controller\\WorkbenchController@delete'); // 删除工作台
Route::post('copy', 'app\\cunkebao\\controller\\WorkbenchController@copy'); // 拷贝工作台
Route::get('detail', 'app\\cunkebao\\controller\\WorkbenchController@detail'); // 获取工作台详情
Route::post('update', 'app\\cunkebao\\controller\\WorkbenchController@update'); // 更新工作台
});
})->middleware(['jwt']);

View File

@@ -0,0 +1,298 @@
<?php
namespace app\cunkebao\controller;
use app\cunkebao\model\ContentLibrary;
use app\cunkebao\model\ContentItem;
use think\Controller;
use think\Db;
/**
* 内容库控制器
*/
class ContentLibraryController extends Controller
{
/**
* 获取内容库列表
* @return \think\response\Json
*/
public function getList()
{
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
$keyword = $this->request->param('keyword', '');
$where = [
['userId', '=', $this->request->userInfo['id']]
];
// 添加名称模糊搜索
if ($keyword !== '') {
$where[] = ['name', 'like', '%' . $keyword . '%'];
}
$list = ContentLibrary::where($where)
->field('id,name,description,createTime,updateTime')
->order('id', 'desc')
->page($page, $limit)
->select();
$total = ContentLibrary::where($where)->count();
return json([
'code' => 200,
'msg' => '获取成功',
'data' => [
'list' => $list,
'total' => $total,
'page' => $page,
'limit' => $limit
]
]);
}
/**
* 获取内容库详情
* @param int $id 内容库ID
* @return \think\response\Json
*/
public function detail($id)
{
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
$library = ContentLibrary::where([
['id', '=', $id],
['userId', '=', $this->request->userInfo['id']]
])
->field('id,name,description,createTime,updateTime')
->find();
if (empty($library)) {
return json(['code' => 404, 'msg' => '内容库不存在']);
}
// 获取内容项目
$items = ContentItem::where('libraryId', $id)->select();
$library['items'] = $items;
return json(['code' => 200, 'msg' => '获取成功', 'data' => $library]);
}
/**
* 创建内容库
* @return \think\response\Json
*/
public function create()
{
if (!$this->request->isPost()) {
return json(['code' => 400, 'msg' => '请求方式错误']);
}
// 获取请求参数
$param = $this->request->post();
// 简单验证
if (empty($param['name'])) {
return json(['code' => 400, 'msg' => '内容库名称不能为空']);
}
Db::startTrans();
try {
// 创建内容库
$library = new ContentLibrary;
$library->name = $param['name'];
$library->description = isset($param['description']) ? $param['description'] : '';
$library->userId = $this->request->userInfo['id'];
$library->companyId = $this->request->userInfo['companyId'];
$library->save();
// 如果有内容项目,也一并创建
if (!empty($param['items']) && is_array($param['items'])) {
foreach ($param['items'] as $item) {
$contentItem = new ContentItem;
$contentItem->libraryId = $library->id;
$contentItem->type = $item['type'];
$contentItem->title = $item['title'] ?? '';
$contentItem->contentData = $item['contentData'];
$contentItem->save();
}
}
Db::commit();
return json(['code' => 200, 'msg' => '创建成功', 'data' => ['id' => $library->id]]);
} catch (\Exception $e) {
Db::rollback();
return json(['code' => 500, 'msg' => '创建失败:' . $e->getMessage()]);
}
}
/**
* 更新内容库
* @return \think\response\Json
*/
public function update()
{
if (!$this->request->isPost()) {
return json(['code' => 400, 'msg' => '请求方式错误']);
}
// 获取请求参数
$param = $this->request->post();
// 简单验证
if (empty($param['id'])) {
return json(['code' => 400, 'msg' => '参数错误']);
}
if (empty($param['name'])) {
return json(['code' => 400, 'msg' => '内容库名称不能为空']);
}
// 查询内容库是否存在
$library = ContentLibrary::where([
['id', '=', $param['id']],
['userId', '=', $this->request->userInfo['id']]
])->find();
if (!$library) {
return json(['code' => 404, 'msg' => '内容库不存在']);
}
Db::startTrans();
try {
// 更新内容库基本信息
$library->name = $param['name'];
$library->description = isset($param['description']) ? $param['description'] : '';
$library->save();
Db::commit();
return json(['code' => 200, 'msg' => '更新成功']);
} catch (\Exception $e) {
Db::rollback();
return json(['code' => 500, 'msg' => '更新失败:' . $e->getMessage()]);
}
}
/**
* 删除内容库
* @param int $id 内容库ID
* @return \think\response\Json
*/
public function delete($id)
{
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
$library = ContentLibrary::where([
['id', '=', $id],
['userId', '=', $this->request->userInfo['id']]
])->find();
if (!$library) {
return json(['code' => 404, 'msg' => '内容库不存在']);
}
Db::startTrans();
try {
// 删除相关内容项目
ContentItem::where('libraryId', $id)->delete();
// 删除内容库
$library->delete();
Db::commit();
return json(['code' => 200, 'msg' => '删除成功']);
} catch (\Exception $e) {
Db::rollback();
return json(['code' => 500, 'msg' => '删除失败:' . $e->getMessage()]);
}
}
/**
* 添加内容项目
* @return \think\response\Json
*/
public function addItem()
{
if (!$this->request->isPost()) {
return json(['code' => 400, 'msg' => '请求方式错误']);
}
// 获取请求参数
$param = $this->request->post();
// A简单验证
if (empty($param['libraryId'])) {
return json(['code' => 400, 'msg' => '内容库ID不能为空']);
}
if (empty($param['type'])) {
return json(['code' => 400, 'msg' => '内容类型不能为空']);
}
if (empty($param['contentData'])) {
return json(['code' => 400, 'msg' => '内容数据不能为空']);
}
// 查询内容库是否存在
$library = ContentLibrary::where([
['id', '=', $param['libraryId']],
['userId', '=', $this->request->userInfo['id']]
])->find();
if (!$library) {
return json(['code' => 404, 'msg' => '内容库不存在']);
}
try {
// 创建内容项目
$item = new ContentItem;
$item->libraryId = $param['libraryId'];
$item->type = $param['type'];
$item->title = $param['title'] ?? '';
$item->contentData = $param['contentData'];
$item->save();
return json(['code' => 200, 'msg' => '添加成功', 'data' => ['id' => $item->id]]);
} catch (\Exception $e) {
return json(['code' => 500, 'msg' => '添加失败:' . $e->getMessage()]);
}
}
/**
* 删除内容项目
* @param int $id 内容项目ID
* @return \think\response\Json
*/
public function deleteItem($id)
{
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
// 查询内容项目是否存在并检查权限
$item = ContentItem::alias('i')
->join('content_library l', 'i.libraryId = l.id')
->where([
['i.id', '=', $id],
['l.userId', '=', $this->request->userInfo['id']]
])
->find();
if (!$item) {
return json(['code' => 404, 'msg' => '内容项目不存在或无权限操作']);
}
try {
// 删除内容项目
ContentItem::destroy($id);
return json(['code' => 200, 'msg' => '删除成功']);
} catch (\Exception $e) {
return json(['code' => 500, 'msg' => '删除失败:' . $e->getMessage()]);
}
}
}

View File

@@ -84,8 +84,11 @@ class WorkbenchController extends Controller
$config->syncInterval = $param['syncInterval'];
$config->syncCount = $param['syncCount'];
$config->syncType = $param['syncType'];
$config->startTime = $param['startTime'];
$config->endTime = $param['endTime'];
$config->accountType = $param['accountType'];
$config->devices = json_encode($param['devices']);
$config->targetGroups = json_encode($param['targetGroups']);
$config->contentLibraries = json_encode($param['contentLibraries'] ?? []);
$config->createTime = time();
$config->updateTime = time();
$config->save();
@@ -155,9 +158,9 @@ class WorkbenchController extends Controller
'autoLike' => function($query) {
$query->field('workbenchId,interval,maxLikes,startTime,endTime,contentTypes,devices,targetGroups');
},
// 'momentsSync' => function($query) {
// $query->field('workbenchId,syncInterval,syncCount,syncType,devices,targetGroups');
// },
'momentsSync' => function($query) {
$query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries');
},
// 'groupPush' => function($query) {
// $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
// },
@@ -188,8 +191,9 @@ class WorkbenchController extends Controller
if (!empty($item->momentsSync)) {
$item->config = $item->momentsSync;
$item->config->devices = json_decode($item->config->devices, true);
$item->config->targetGroups = json_decode($item->config->targetGroups, true);
$item->config->contentLibraries = json_decode($item->config->contentLibraries, true);
}
unset($item->momentsSync,$item->moments_sync);
break;
case self::TYPE_GROUP_PUSH:
if (!empty($item->groupPush)) {
@@ -199,6 +203,7 @@ class WorkbenchController extends Controller
$item->config->pushContent = json_decode($item->config->pushContent, true);
$item->config->pushTime = json_decode($item->config->pushTime, true);
}
unset($item->groupPush,$item->group_push);
break;
case self::TYPE_GROUP_CREATE:
if (!empty($item->groupCreate)) {
@@ -206,9 +211,9 @@ class WorkbenchController extends Controller
$item->config->devices = json_decode($item->config->devices, true);
$item->config->targetGroups = json_decode($item->config->targetGroups, true);
}
unset($item->groupCreate,$item->group_create);
break;
}
unset( $item->momentsSync, $item->groupPush, $item->groupCreate);
return $item;
});
@@ -231,8 +236,10 @@ class WorkbenchController extends Controller
* @param int $id 工作台ID
* @return \think\response\Json
*/
public function detail($id)
public function detail()
{
$id = $this->request->param('id', '');
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
@@ -243,14 +250,14 @@ class WorkbenchController extends Controller
$query->field('workbenchId,interval,maxLikes,startTime,endTime,contentTypes,devices,targetGroups');
},
'momentsSync' => function($query) {
$query->field('workbenchId,syncInterval,syncCount,syncType,devices,targetGroups');
$query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries');
},
'groupPush' => function($query) {
$query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
},
'groupCreate' => function($query) {
$query->field('workbenchId,groupNamePrefix,maxGroups,membersPerGroup,devices,targetGroups');
}
// 'groupPush' => function($query) {
// $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
// },
// 'groupCreate' => function($query) {
// $query->field('workbenchId,groupNamePrefix,maxGroups,membersPerGroup,devices,targetGroups');
// }
];
$workbench = Workbench::where([
@@ -273,14 +280,15 @@ class WorkbenchController extends Controller
$workbench->config = $workbench->autoLike;
$workbench->config->devices = json_decode($workbench->config->devices, true);
$workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true);
$workbench->config->contentTypes = explode(',', $workbench->config->contentTypes);
$workbench->config->contentTypes = json_decode($workbench->config->contentTypes, true);
unset($workbench->autoLike,$workbench->auto_like);
}
break;
case self::TYPE_MOMENTS_SYNC:
if (!empty($workbench->momentsSync)) {
$workbench->config = $workbench->momentsSync;
$workbench->config->devices = json_decode($workbench->config->devices, true);
$workbench->config->targetGroups = json_decode($workbench->config->targetGroups, true);
$workbench->config->contentLibraries = json_decode($workbench->config->contentLibraries, true);
}
break;
case self::TYPE_GROUP_PUSH:
@@ -305,6 +313,112 @@ class WorkbenchController extends Controller
return json(['code' => 200, 'msg' => '获取成功', 'data' => $workbench]);
}
/**
* 更新工作台
* @return \think\response\Json
*/
public function update()
{
if (!$this->request->isPost()) {
return json(['code' => 400, 'msg' => '请求方式错误']);
}
// 获取请求参数
$param = $this->request->post();
// 验证数据
$validate = new WorkbenchValidate;
if (!$validate->scene('update')->check($param)) {
return json(['code' => 400, 'msg' => $validate->getError()]);
}
// 查询工作台是否存在
$workbench = Workbench::where([
['id', '=', $param['id']],
['userId', '=', $this->request->userInfo['id']],
['isDel', '=', 0]
])->find();
if (!$workbench) {
return json(['code' => 404, 'msg' => '工作台不存在']);
}
Db::startTrans();
try {
// 更新工作台基本信息
$workbench->name = $param['name'];
$workbench->autoStart = !empty($param['autoStart']) ? 1 : 0;
$workbench->updateTime = time();
$workbench->save();
// 根据类型更新对应的配置
switch ($workbench->type) {
case self::TYPE_AUTO_LIKE:
$config = WorkbenchAutoLike::where('workbenchId', $param['id'])->find();
if ($config) {
$config->interval = $param['interval'];
$config->maxLikes = $param['maxLikes'];
$config->startTime = $param['startTime'];
$config->endTime = $param['endTime'];
$config->contentTypes = json_encode($param['contentTypes']);
$config->devices = json_encode($param['devices']);
$config->targetGroups = json_encode($param['targetGroups']);
$config->tagOperator = $param['tagOperator'];
$config->updateTime = time();
$config->save();
}
break;
case self::TYPE_MOMENTS_SYNC:
$config = WorkbenchMomentsSync::where('workbenchId', $param['id'])->find();
if ($config) {
$config->syncInterval = $param['syncInterval'];
$config->syncCount = $param['syncCount'];
$config->syncType = $param['syncType'];
$config->startTime = $param['startTime'];
$config->endTime = $param['endTime'];
$config->accountType = $param['accountType'];
$config->devices = json_encode($param['devices']);
$config->contentLibraries = json_encode($param['contentLibraries'] ?? []);
$config->updateTime = time();
$config->save();
}
break;
case self::TYPE_GROUP_PUSH:
$config = WorkbenchGroupPush::where('workbenchId', $param['id'])->find();
if ($config) {
$config->pushInterval = $param['pushInterval'];
$config->pushContent = json_encode($param['pushContent']);
$config->pushTime = json_encode($param['pushTime']);
$config->devices = json_encode($param['devices']);
$config->targetGroups = json_encode($param['targetGroups']);
$config->save();
}
break;
case self::TYPE_GROUP_CREATE:
$config = WorkbenchGroupCreate::where('workbenchId', $param['id'])->find();
if ($config) {
$config->groupNamePrefix = $param['groupNamePrefix'];
$config->maxGroups = $param['maxGroups'];
$config->membersPerGroup = $param['membersPerGroup'];
$config->devices = json_encode($param['devices']);
$config->targetGroups = json_encode($param['targetGroups']);
$config->updateTime = time();
$config->save();
}
break;
}
Db::commit();
return json(['code' => 200, 'msg' => '更新成功']);
} catch (\Exception $e) {
Db::rollback();
return json(['code' => 500, 'msg' => '更新失败:' . $e->getMessage()]);
}
}
/**
* 更新工作台状态
* @return \think\response\Json
@@ -341,8 +455,9 @@ class WorkbenchController extends Controller
/**
* 删除工作台(软删除)
*/
public function delete($id)
public function delete()
{
$id = $this->request->param('id');
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
@@ -399,6 +514,7 @@ class WorkbenchController extends Controller
$newWorkbench->status = 1; // 新拷贝的默认启用
$newWorkbench->autoStart = $workbench->autoStart;
$newWorkbench->userId = $this->request->userInfo['id'];
$newWorkbench->companyId = $this->request->userInfo['companyId'];
$newWorkbench->save();
// 根据类型拷贝对应的配置
@@ -426,8 +542,11 @@ class WorkbenchController extends Controller
$newConfig->syncInterval = $config->syncInterval;
$newConfig->syncCount = $config->syncCount;
$newConfig->syncType = $config->syncType;
$newConfig->startTime = $config->startTime;
$newConfig->endTime = $config->endTime;
$newConfig->accountType = $config->accountType;
$newConfig->devices = $config->devices;
$newConfig->targetGroups = $config->targetGroups;
$newConfig->contentLibraries = $config->contentLibraries;
$newConfig->save();
}
break;

View File

@@ -0,0 +1,52 @@
<?php
namespace app\cunkebao\model;
use think\Model;
class ContentItem extends Model
{
protected $pk = 'id';
protected $name = 'content_items';
// 内容类型
const TYPE_TEXT = 1; // 文本
const TYPE_IMAGE = 2; // 图片
const TYPE_VIDEO = 3; // 视频
const TYPE_LINK = 4; // 链接
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
// 定义关联的内容库
public function library()
{
return $this->belongsTo('ContentLibrary', 'libraryId', 'id');
}
// 内容类型获取器
public function getTypeTextAttr($value, $data)
{
$types = [
self::TYPE_TEXT => '文本',
self::TYPE_IMAGE => '图片',
self::TYPE_VIDEO => '视频',
self::TYPE_LINK => '链接'
];
return isset($types[$data['type']]) ? $types[$data['type']] : '未知';
}
// 内容数据获取器
public function getContentDataAttr($value)
{
return json_decode($value, true);
}
// 内容数据修改器
public function setContentDataAttr($value)
{
return is_array($value) ? json_encode($value) : $value;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace app\cunkebao\model;
use think\Model;
class ContentLibrary extends Model
{
protected $pk = 'id';
protected $name = 'content_library';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
// 定义关联的用户
public function user()
{
return $this->belongsTo('User', 'userId', 'id');
}
// 定义关联的内容项目
public function items()
{
return $this->hasMany('ContentItem', 'libraryId', 'id');
}
// 根据ID数组获取内容库列表
public static function getByIds($ids)
{
if (empty($ids)) {
return [];
}
return self::where('id', 'in', $ids)->select();
}
}

View File

@@ -9,6 +9,12 @@ class WorkbenchMomentsSync extends Model
protected $pk = 'id';
protected $name = 'workbench_moments_sync';
// 同步类型
const SYNC_TYPE_TEXT = 1; // 文本
const SYNC_TYPE_IMAGE = 2; // 图片
const SYNC_TYPE_VIDEO = 3; // 视频
const SYNC_TYPE_LINK = 4; // 链接
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
@@ -19,4 +25,34 @@ class WorkbenchMomentsSync extends Model
{
return $this->belongsTo('Workbench', 'workbenchId', 'id');
}
// 定义关联的内容库
public function contentLibraries()
{
return $this->belongsToMany('ContentLibrary', 'workbench_content_relation', 'contentLibraryId', 'workbenchId');
}
// 开始时间获取器
public function getStartTimeAttr($value)
{
return $value ? date('H:i', strtotime($value)) : '';
}
// 结束时间获取器
public function getEndTimeAttr($value)
{
return $value ? date('H:i', strtotime($value)) : '';
}
// 同步类型获取器
public function getSyncTypeTextAttr($value, $data)
{
$types = [
self::SYNC_TYPE_TEXT => '文本',
self::SYNC_TYPE_IMAGE => '图片',
self::SYNC_TYPE_VIDEO => '视频',
self::SYNC_TYPE_LINK => '链接'
];
return isset($types[$data['syncType']]) ? $types[$data['syncType']] : '未知';
}
}

View File

@@ -25,10 +25,15 @@ class Workbench extends Validate
'startTime' => 'requireIf:type,1|dateFormat:H:i',
'endTime' => 'requireIf:type,1|dateFormat:H:i',
'contentTypes' => 'requireIf:type,1|array|contentTypeEnum:text,image,video',
'targetGroups' => 'requireIf:type,1|array',
// 朋友圈同步特有参数
'syncInterval' => 'requireIf:type,2|number|min:1',
'syncCount' => 'requireIf:type,2|number|min:1',
'syncType' => 'requireIf:type,2|in:1,2,3,4',
'startTime' => 'requireIf:type,2|dateFormat:H:i',
'endTime' => 'requireIf:type,2|dateFormat:H:i',
'accountType' => 'requireIf:type,2|in:1,2',
'contentLibraries' => 'requireIf:type,2|array',
// 群消息推送特有参数
'pushInterval' => 'requireIf:type,3|number|min:1',
'pushContent' => 'requireIf:type,3|array',
@@ -39,7 +44,6 @@ class Workbench extends Validate
'membersPerGroup' => 'requireIf:type,4|number|min:1',
// 通用参数
'devices' => 'require|array',
'targetGroups' => 'require|array'
];
/**
@@ -75,6 +79,14 @@ class Workbench extends Validate
'syncCount.min' => '同步数量必须大于0',
'syncType.requireIf' => '请选择同步类型',
'syncType.in' => '同步类型错误',
'startTime.requireIf' => '请设置发布开始时间',
'startTime.dateFormat' => '发布开始时间格式错误',
'endTime.requireIf' => '请设置发布结束时间',
'endTime.dateFormat' => '发布结束时间格式错误',
'accountType.requireIf' => '请选择账号类型',
'accountType.in' => '账号类型错误',
'contentLibraries.requireIf' => '请选择内容库',
'contentLibraries.array' => '内容库格式错误',
// 群消息推送相关提示
'pushInterval.requireIf' => '请设置推送间隔',
'pushInterval.number' => '推送间隔必须为数字',

View File

@@ -6,6 +6,7 @@ use think\queue\Job;
use think\facade\Log;
use think\Queue;
use think\facade\Config;
use think\facade\Cache;
use app\api\controller\WechatFriendController;
class WechatFriendJob
@@ -58,7 +59,7 @@ class WechatFriendJob
$pageSize = isset($data['pageSize']) ? $data['pageSize'] : 1000;
$preFriendId = isset($data['preFriendId']) ? $data['preFriendId'] : '';
Log::info('开始获取微信列表,页码:' . $pageIndex . ',页大小:' . $pageSize);
Log::info('开始获取微信列表,页码:' . $pageIndex . ',页大小:' . $pageSize . '上一好友ID' . $preFriendId);
// 实例化控制器
$wechatFriendController = new WechatFriendController();
@@ -86,10 +87,24 @@ class WechatFriendJob
// 判断是否有下一页
if (!empty($data) && count($data) > 0) {
// 获取最后一条记录的ID
$lastFriendId = $data[count($data)-1]['id'];
// 更新缓存中的页码和最后一个好友ID设置10分钟过期
Cache::set('friendsPage', $pageIndex + 1, 600);
Cache::set('preFriendId', $lastFriendId, 600);
Log::info('更新缓存,下一页页码:' . ($pageIndex + 1) . '最后好友ID' . $lastFriendId . '缓存时间10分钟');
// 有下一页,将下一页任务添加到队列
$nextPageIndex = $pageIndex + 1;
$this->addNextPageToQueue($nextPageIndex, $pageSize,$data[count($data)-1]['id']);
$this->addNextPageToQueue($nextPageIndex, $pageSize, $lastFriendId);
Log::info('添加下一页任务到队列,页码:' . $nextPageIndex);
} else {
// 没有下一页重置缓存设置10分钟过期
Cache::set('friendsPage', 0, 600);
Cache::set('preFriendId', '', 600);
Log::info('获取完成重置缓存缓存时间10分钟');
}
return true;
@@ -104,6 +119,7 @@ class WechatFriendJob
* 添加下一页任务到队列
* @param int $pageIndex 页码
* @param int $pageSize 每页大小
* @param string $preFriendId 上一个好友ID
*/
protected function addNextPageToQueue($pageIndex, $pageSize,$preFriendId)
{