From 9a0faa3a46cec934305b8b2aca1fba4a23cb7049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Fri, 16 May 2025 17:40:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98?= =?UTF-8?q?=E6=89=8B=20-=20=E4=BC=98=E5=8C=96=E8=B0=83=E6=95=B4=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/devices/[id]/page.tsx | 231 +++++++++++++++++------------ 1 file changed, 135 insertions(+), 96 deletions(-) diff --git a/Cunkebao/app/devices/[id]/page.tsx b/Cunkebao/app/devices/[id]/page.tsx index 8058b7f5..51d89b4d 100644 --- a/Cunkebao/app/devices/[id]/page.tsx +++ b/Cunkebao/app/devices/[id]/page.tsx @@ -76,6 +76,7 @@ interface HandleLog { export default function DeviceDetailPage() { const params = useParams() + const deviceId = params?.id as string const router = useRouter() const [device, setDevice] = useState(null) const [activeTab, setActiveTab] = useState("info") @@ -94,12 +95,15 @@ export default function DeviceDetailPage() { aiChat: false }) const [tabChangeLoading, setTabChangeLoading] = useState(false) + const [accountPage, setAccountPage] = useState(1) + const [hasMoreAccounts, setHasMoreAccounts] = useState(true) + const accountsPerPage = 10 + const accountsEndRef = useRef(null) // 添加登录检查 useEffect(() => { const token = localStorage.getItem('token') if (!token) { - // 如果没有token,重定向到登录页面,并携带当前页面URL作为回调 const currentPath = window.location.pathname + window.location.search router.push(`/login?redirect=${encodeURIComponent(currentPath)}`) return @@ -107,12 +111,12 @@ export default function DeviceDetailPage() { }, [router]) useEffect(() => { - if (!params.id) return + if (!deviceId) return const fetchDevice = async () => { try { setLoading(true) - const response = await fetchDeviceDetail(params.id as string) + const response = await fetchDeviceDetail(deviceId) if (response && response.code === 200 && response.data) { const serverData = response.data @@ -140,7 +144,6 @@ export default function DeviceDetailPage() { // 解析features if (serverData.features) { - // 如果后端直接返回了features对象,使用它 formattedDevice.features = { autoAddFriend: Boolean(serverData.features.autoAddFriend), autoReply: Boolean(serverData.features.autoReply), @@ -149,7 +152,6 @@ export default function DeviceDetailPage() { } } else if (serverData.taskConfig) { try { - // 解析taskConfig字段 const taskConfig = JSON.parse(serverData.taskConfig || '{}'); if (taskConfig) { @@ -165,57 +167,33 @@ export default function DeviceDetailPage() { } } - // 如果有微信账号信息,构建微信账号对象 - if (serverData.wechatId) { - formattedDevice.wechatAccounts = [ - { - id: serverData.wechatId?.toString() || "1", - avatar: "/placeholder.svg", // 默认头像 - nickname: serverData.memo || "微信账号", - wechatId: serverData.imei || "", - gender: 1, // 默认性别 - status: serverData.alive === 1 ? 1 : 0, - statusText: serverData.alive === 1 ? "可加友" : "已停用", - wechatAlive: serverData.alive === 1 ? 1 : 0, - wechatAliveText: serverData.alive === 1 ? "正常" : "异常", - addFriendStatus: 1, - totalFriend: serverData.totalFriend || 0, - lastActive: serverData.lastUpdateTime || new Date().toISOString() - } - ] - } - setDevice(formattedDevice) - // 如果当前激活标签是"accounts",则加载关联微信账号 + // 如果当前激活标签是"accounts",则立即加载关联微信账号 if (activeTab === "accounts") { fetchRelatedAccounts() } } else { - // 如果API返回错误,显示错误提示 toast.error("获取设备信息失败: " + ((response as any)?.msg || "未知错误")) - setLoading(false) } } catch (error) { console.error("获取设备信息失败:", error) toast.error("获取设备信息出错,请稍后重试") - setLoading(false) } finally { - // 确保loading状态被关闭 setLoading(false) } } fetchDevice() - }, [params.id, activeTab]) + }, [deviceId]) // 使用 deviceId 替代 params.id // 获取设备关联微信账号 - const fetchRelatedAccounts = async () => { - if (!params.id || accountsLoading) return + const fetchRelatedAccounts = async (page = 1) => { + if (!deviceId || accountsLoading) return try { setAccountsLoading(true) - const response = await fetchDeviceRelatedAccounts(params.id as string) + const response = await fetchDeviceRelatedAccounts(deviceId) if (response && response.code === 200 && response.data) { const accounts = response.data.accounts || [] @@ -225,21 +203,20 @@ export default function DeviceDetailPage() { if (!prev) return null return { ...prev, - wechatAccounts: accounts + // 如果是第一页,替换数据;否则追加数据 + wechatAccounts: page === 1 + ? accounts + : [...(prev.wechatAccounts || []), ...accounts] } }) - if (accounts.length > 0) { - toast.success(`成功获取${accounts.length}个关联微信账号`) - } else { - toast.info("此设备暂无关联微信账号") - } + // 判断是否还有更多数据 + setHasMoreAccounts(accounts.length === accountsPerPage) } else { - toast.error("获取关联微信账号失败") + console.error("获取关联微信账号失败") } } catch (error) { console.error("获取关联微信账号失败:", error) - toast.error("获取关联微信账号出错") } finally { setAccountsLoading(false) } @@ -247,12 +224,12 @@ export default function DeviceDetailPage() { // 获取设备操作记录 const fetchHandleLogs = async () => { - if (!params.id || logsLoading) return + if (!deviceId || logsLoading) return try { setLogsLoading(true) const response = await fetchDeviceHandleLogs( - params.id as string, + deviceId, logPage, logsPerPage ) @@ -527,6 +504,51 @@ export default function DeviceDetailPage() { return nameMap[feature] || feature } + // 加载更多账号 + const loadMoreAccounts = () => { + if (accountsLoading || !hasMoreAccounts) return + setAccountPage(prev => prev + 1) + fetchRelatedAccounts(accountPage + 1) + } + + // 监听账号列表滚动加载更多 + useEffect(() => { + if (activeTab !== "accounts") return + + const observerOptions = { + root: null, + rootMargin: '0px', + threshold: 0.1 + } + + const handleIntersect = (entries: IntersectionObserverEntry[]) => { + const [entry] = entries + if (entry.isIntersecting && hasMoreAccounts && !accountsLoading) { + loadMoreAccounts() + } + } + + const observer = new IntersectionObserver(handleIntersect, observerOptions) + + if (accountsEndRef.current) { + observer.observe(accountsEndRef.current) + } + + return () => { + if (accountsEndRef.current) { + observer.unobserve(accountsEndRef.current) + } + } + }, [activeTab, hasMoreAccounts, accountsLoading]) + + // 当切换到账号标签时重置页码 + useEffect(() => { + if (activeTab === "accounts") { + setAccountPage(1) + setHasMoreAccounts(true) + } + }, [activeTab]) + if (loading) { return (
@@ -547,7 +569,7 @@ export default function DeviceDetailPage() {
设备不存在或已被删除
- 无法加载ID为 "{params.id}" 的设备信息,请检查设备是否存在。 + 无法加载ID为 "{deviceId}" 的设备信息,请检查设备是否存在。
- + {/* 标签切换时的加载状态 */} {tabChangeLoading && (
@@ -735,14 +774,13 @@ export default function DeviceDetailPage() {
)} - {accountsLoading && ( + + {accountsLoading && !device?.wechatAccounts?.length ? (
加载微信账号中...
- )} - - {!accountsLoading && device.wechatAccounts && device.wechatAccounts.length > 0 ? ( + ) : device?.wechatAccounts && device.wechatAccounts.length > 0 ? (
{device.wechatAccounts.map((account) => (
@@ -770,22 +808,44 @@ export default function DeviceDetailPage() {
))} + + {/* 加载更多区域 */} +
+ {accountsLoading && hasMoreAccounts ? ( +
+
+ 加载更多... +
+ ) : hasMoreAccounts ? ( + + ) : device.wechatAccounts.length > 0 && ( + - 已加载全部记录 - + )} +
) : ( - !accountsLoading && ( -
-

此设备暂无关联的微信账号

- -
- ) +
+

此设备暂无关联的微信账号

+ +
)}
@@ -894,27 +954,6 @@ export default function DeviceDetailPage() { - -
- -
- - 好友总数 -
-
- {(device.totalFriend || 0).toLocaleString()} -
-
- -
- - 消息数量 -
-
- {(device.thirtyDayMsgCount || 0).toLocaleString()} -
-
-
From 7111d4888634659064a4e8154342ad19bfa900e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Fri, 16 May 2025 17:47:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98?= =?UTF-8?q?=E6=89=8B=20-=20=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=98=BE=E7=A4=BA=E5=AE=8C=E6=95=B4IMEI=EF=BC=8C?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=9F=A5=E7=9C=8BIMEI=E7=9A=84=E6=A8=A1?= =?UTF-8?q?=E6=80=81=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/devices/page.tsx | 13 ++----------- Server/application/cunkebao/config/route.php | 1 + 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Cunkebao/app/devices/page.tsx b/Cunkebao/app/devices/page.tsx index c717b706..4a5e3a4d 100644 --- a/Cunkebao/app/devices/page.tsx +++ b/Cunkebao/app/devices/page.tsx @@ -559,14 +559,6 @@ export default function DevicesPage() { return; } - let target = event.target as HTMLElement; - while (target && target !== event.currentTarget) { - if (target.classList.contains('imei-display-area')) { - return; - } - target = target.parentElement as HTMLElement; - } - router.push(`/devices/${deviceId}`); } @@ -715,9 +707,8 @@ export default function DevicesPage() { {device.status === "online" ? "在线" : "离线"} -
- IMEI: - +
+ IMEI: {device.imei}
微信号: {device.wechatId || "未绑定或微信离线"}
diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index 43a658b7..b2efda2f 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -12,6 +12,7 @@ Route::group('v1/', function () { Route::put('refresh', 'app\cunkebao\controller\device\RefreshDeviceDetailV1Controller@index'); Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedV1Controller@index'); Route::post('task-config', 'app\cunkebao\controller\device\UpdateDeviceTaskConfigV1Controller@index'); + Route::get(':id/task-config', 'app\cunkebao\controller\device\UpdateDeviceTaskConfigV1Controller@index'); Route::get(':id/handle-logs', 'app\cunkebao\controller\device\GetDeviceHandleLogsV1Controller@index'); Route::get(':id', 'app\cunkebao\controller\device\GetDeviceDetailV1Controller@index'); Route::delete(':id', 'app\cunkebao\controller\device\DeleteDeviceV1Controller@index'); From bff2d5eb8b95d713aa088f9e73c9f8e2c3b77f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Fri, 16 May 2025 18:32:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98?= =?UTF-8?q?=E6=89=8B=20-=20=E8=AE=BE=E5=A4=87=E9=85=8D=E7=BD=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8F=90=E4=BE=9B=E6=9C=80=E5=B0=8F=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=8D=95=E5=85=83=EF=BC=8C=E4=B8=8E=E8=AE=BE=E5=A4=87=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/components/device-grid.tsx | 322 ++++++++++++------ Cunkebao/app/devices/[id]/page.tsx | 37 ++ Cunkebao/styles/globals.css | 71 ++-- Server/application/cunkebao/config/route.php | 2 +- .../device/GetDeviceDetailV1Controller.php | 77 ----- .../GetDeviceTaskConfigV1Controller.php | 85 +++++ 6 files changed, 385 insertions(+), 209 deletions(-) create mode 100644 Server/application/cunkebao/controller/device/GetDeviceTaskConfigV1Controller.php diff --git a/Cunkebao/app/components/device-grid.tsx b/Cunkebao/app/components/device-grid.tsx index 028119a7..097b2dce 100644 --- a/Cunkebao/app/components/device-grid.tsx +++ b/Cunkebao/app/components/device-grid.tsx @@ -1,12 +1,15 @@ "use client" -import { useState } from "react" +import { useState, useEffect } from "react" import { Card } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog" -import { Battery, Smartphone, MessageCircle, Users, Clock } from "lucide-react" +import { Battery, Smartphone, MessageCircle, Users, Clock, Search, Power, RefreshCcw, Settings, AlertTriangle } from "lucide-react" import { ImeiDisplay } from "@/components/ImeiDisplay" +import { Input } from "@/components/ui/input" +import { Button } from "@/components/ui/button" +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" export interface Device { id: string @@ -38,32 +41,55 @@ export function DeviceGrid({ itemsPerRow = 2, }: DeviceGridProps) { const [selectedDevice, setSelectedDevice] = useState(null) + const [searchTerm, setSearchTerm] = useState("") + const [filteredDevices, setFilteredDevices] = useState(devices) + + useEffect(() => { + const filtered = devices.filter( + (device) => + device.name.toLowerCase().includes(searchTerm.toLowerCase()) || + device.imei.includes(searchTerm) || + device.wechatId.toLowerCase().includes(searchTerm.toLowerCase()) + ) + setFilteredDevices(filtered) + }, [searchTerm, devices]) const handleSelectAll = () => { - if (selectedDevices.length === devices.length) { + if (selectedDevices.length === filteredDevices.length) { onSelect?.([]) } else { - onSelect?.(devices.map((d) => d.id)) + onSelect?.(filteredDevices.map((d) => d.id)) } } return (
- {selectable && ( -
-
- 0} - onCheckedChange={handleSelectAll} - /> - 全选 -
- 已选择 {selectedDevices.length} 个设备 +
+
+ + setSearchTerm(e.target.value)} + />
- )} + {selectable && ( +
+
+ 0} + onCheckedChange={handleSelectAll} + /> + 全选 +
+ 已选择 {selectedDevices.length} 个设备 +
+ )} +
-
- {devices.map((device) => ( +
+ {filteredDevices.map((device) => (
-
{device.name}
-
- - {device.status === "online" ? "在线" : "离线"} +
+ {device.name} + {device.addFriendStatus === "abnormal" && ( + + 加友异常 + + )} +
+
+ +
+
+ {device.status === "online" ? "在线" : "离线"} +
-
-
- - {device.battery}% +
+
+ + {device.battery}%
-
- - {device.friendCount} +
+ + {device.friendCount}
-
- - {device.messageCount} +
+ + {device.messageCount}
-
- - +{device.todayAdded} +
+ + +{device.todayAdded}
-
-
IMEI: {device.imei}
-
微信号: {device.wechatId}
+
+
+ IMEI: + +
+
+ 微信号: + {device.wechatId} +
- - - {device.addFriendStatus === "normal" ? "加友正常" : "加友异常"} -
@@ -134,77 +193,144 @@ export function DeviceGrid({
setSelectedDevice(null)}> - + 设备详情 {selectedDevice && ( -
+
-
- +
+
-

{selectedDevice.name}

-

- IMEI: - -

+

+ {selectedDevice.name} + +
+
+ {selectedDevice.status === "online" ? "在线" : "离线"} +
+ +

+
+ IMEI: + 微信号: {selectedDevice.wechatId} +
- - {selectedDevice.status === "online" ? "在线" : "离线"} - -
- -
-
-
电池电量
-
- - {selectedDevice.battery}% -
-
-
-
好友数量
-
- - {selectedDevice.friendCount} -
-
-
-
今日新增
-
- - +{selectedDevice.todayAdded} -
-
-
-
消息数量
-
- - {selectedDevice.messageCount} -
+
+ + +
-
-
微信账号
-
{selectedDevice.wechatId}
-
+ + + 状态信息 + 统计数据 + 任务管理 + 运行日志 + + +
+
+
电池电量
+
+ + {selectedDevice.battery}% +
+
+
+
好友数量
+
+ + {selectedDevice.friendCount} +
+
+
+
今日新增
+
+ + +{selectedDevice.todayAdded} +
+
+
+
消息数量
+
+ + {selectedDevice.messageCount} +
+
+
-
-
最后活跃
-
{selectedDevice.lastActive}
-
- -
-
加友状态
- - {selectedDevice.addFriendStatus === "normal" ? "加友正常" : "加友异常"} - -
+ {selectedDevice.addFriendStatus === "abnormal" && ( +
+
+ + 加友异常警告 +
+

+ 该设备当前存在加友异常情况,请检查设备状态和相关配置。 +

+
+ )} +
+ +
+ 统计数据开发中... +
+
+ +
+ 任务管理开发中... +
+
+ +
+ 运行日志开发中... +
+
+
)} diff --git a/Cunkebao/app/devices/[id]/page.tsx b/Cunkebao/app/devices/[id]/page.tsx index 51d89b4d..fe0c18ed 100644 --- a/Cunkebao/app/devices/[id]/page.tsx +++ b/Cunkebao/app/devices/[id]/page.tsx @@ -13,6 +13,7 @@ import { ScrollArea } from "@/components/ui/scroll-area" import { fetchDeviceDetail, fetchDeviceRelatedAccounts, updateDeviceTaskConfig, fetchDeviceHandleLogs } from "@/api/devices" import { toast } from "sonner" import { ImeiDisplay } from "@/components/ImeiDisplay" +import { api } from "@/lib/api" interface WechatAccount { id: string @@ -315,6 +316,37 @@ export default function DeviceDetailPage() { } }, [logPage, activeTab]) + // 获取任务配置 + const fetchTaskConfig = async () => { + try { + const response = await api.get(`/v1/devices/${deviceId}/task-config`) + + if (response && response.code === 200 && response.data) { + setDevice(prev => { + if (!prev) return null + return { + ...prev, + features: { + autoAddFriend: Boolean(response.data.autoAddFriend), + autoReply: Boolean(response.data.autoReply), + momentsSync: Boolean(response.data.momentsSync), + aiChat: Boolean(response.data.aiChat) + } + } + }) + } + } catch (error) { + console.error("获取任务配置失败:", error) + } + } + + // 在组件加载时获取任务配置 + useEffect(() => { + if (deviceId) { + fetchTaskConfig() + } + }, [deviceId]) + // 处理标签页切换 const handleTabChange = (value: string) => { setActiveTab(value) @@ -331,6 +363,11 @@ export default function DeviceDetailPage() { if (value === "history") { fetchHandleLogs() } + + // 当切换到"基本信息"标签时,获取最新的任务配置 + if (value === "info") { + fetchTaskConfig() + } // 设置短暂的延迟来关闭加载状态,模拟加载过程 setTimeout(() => { diff --git a/Cunkebao/styles/globals.css b/Cunkebao/styles/globals.css index ac684423..1623bf9c 100644 --- a/Cunkebao/styles/globals.css +++ b/Cunkebao/styles/globals.css @@ -15,24 +15,24 @@ body { @layer base { :root { --background: 0 0% 100%; - --foreground: 0 0% 3.9%; + --foreground: 222.2 84% 4.9%; --card: 0 0% 100%; - --card-foreground: 0 0% 3.9%; + --card-foreground: 222.2 84% 4.9%; --popover: 0 0% 100%; - --popover-foreground: 0 0% 3.9%; - --primary: 0 0% 9%; - --primary-foreground: 0 0% 98%; - --secondary: 0 0% 96.1%; - --secondary-foreground: 0 0% 9%; - --muted: 0 0% 96.1%; - --muted-foreground: 0 0% 45.1%; - --accent: 0 0% 96.1%; - --accent-foreground: 0 0% 9%; + --popover-foreground: 222.2 84% 4.9%; + --primary: 222.2 47.4% 11.2%; + --primary-foreground: 210 40% 98%; + --secondary: 210 40% 96.1%; + --secondary-foreground: 222.2 47.4% 11.2%; + --muted: 210 40% 96.1%; + --muted-foreground: 215.4 16.3% 46.9%; + --accent: 210 40% 96.1%; + --accent-foreground: 222.2 47.4% 11.2%; --destructive: 0 84.2% 60.2%; - --destructive-foreground: 0 0% 98%; - --border: 0 0% 89.8%; - --input: 0 0% 89.8%; - --ring: 0 0% 3.9%; + --destructive-foreground: 210 40% 98%; + --border: 214.3 31.8% 91.4%; + --input: 214.3 31.8% 91.4%; + --ring: 215 20.2% 65.1%; --chart-1: 12 76% 61%; --chart-2: 173 58% 39%; --chart-3: 197 37% 24%; @@ -49,25 +49,25 @@ body { --sidebar-ring: 217.2 91.2% 59.8%; } .dark { - --background: 0 0% 3.9%; - --foreground: 0 0% 98%; - --card: 0 0% 3.9%; - --card-foreground: 0 0% 98%; - --popover: 0 0% 3.9%; - --popover-foreground: 0 0% 98%; - --primary: 0 0% 98%; - --primary-foreground: 0 0% 9%; - --secondary: 0 0% 14.9%; - --secondary-foreground: 0 0% 98%; - --muted: 0 0% 14.9%; - --muted-foreground: 0 0% 63.9%; - --accent: 0 0% 14.9%; - --accent-foreground: 0 0% 98%; + --background: 222.2 84% 4.9%; + --foreground: 210 40% 98%; + --card: 222.2 84% 4.9%; + --card-foreground: 210 40% 98%; + --popover: 222.2 84% 4.9%; + --popover-foreground: 210 40% 98%; + --primary: 210 40% 98%; + --primary-foreground: 222.2 47.4% 11.2%; + --secondary: 217.2 32.6% 17.5%; + --secondary-foreground: 210 40% 98%; + --muted: 217.2 32.6% 17.5%; + --muted-foreground: 215 20.2% 65.1%; + --accent: 217.2 32.6% 17.5%; + --accent-foreground: 210 40% 98%; --destructive: 0 62.8% 30.6%; - --destructive-foreground: 0 0% 98%; - --border: 0 0% 14.9%; - --input: 0 0% 14.9%; - --ring: 0 0% 83.1%; + --destructive-foreground: 0 85.7% 97.3%; + --border: 217.2 32.6% 17.5%; + --input: 217.2 32.6% 17.5%; + --ring: 217.2 32.6% 17.5%; --chart-1: 220 70% 50%; --chart-2: 160 60% 45%; --chart-3: 30 80% 55%; @@ -92,3 +92,8 @@ body { @apply bg-background text-foreground; } } + +/* 隐藏 Next.js 静态指示器 */ +.nextjs-static-indicator-toast-wrapper { + display: none !important; +} diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index b2efda2f..af78ca1b 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -12,7 +12,7 @@ Route::group('v1/', function () { Route::put('refresh', 'app\cunkebao\controller\device\RefreshDeviceDetailV1Controller@index'); Route::get('add-results', 'app\cunkebao\controller\device\GetAddResultedV1Controller@index'); Route::post('task-config', 'app\cunkebao\controller\device\UpdateDeviceTaskConfigV1Controller@index'); - Route::get(':id/task-config', 'app\cunkebao\controller\device\UpdateDeviceTaskConfigV1Controller@index'); + Route::get(':id/task-config', 'app\cunkebao\controller\device\GetDeviceTaskConfigV1Controller@index'); Route::get(':id/handle-logs', 'app\cunkebao\controller\device\GetDeviceHandleLogsV1Controller@index'); Route::get(':id', 'app\cunkebao\controller\device\GetDeviceDetailV1Controller@index'); Route::delete(':id', 'app\cunkebao\controller\device\DeleteDeviceV1Controller@index'); diff --git a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php index b9c92600..e42f5a9e 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php @@ -59,29 +59,6 @@ class GetDeviceDetailV1Controller extends BaseController return 0; } - /** - * 解析taskConfig字段获取功能开关 - * - * @param int $deviceId - * @return int[] - * @throws \Exception - */ - protected function getTaskConfig(int $deviceId): array - { - $conf = DeviceTaskconfModel::alias('c')->field([ - 'c.autoAddFriend', 'c.autoReply', 'c.momentsSync', 'c.aiChat' - ]) - ->where( - [ - 'companyId' => $this->getUserInfo('companyId'), - 'deviceId' => $deviceId - ] - ) - ->find(); - - // 未配置时赋予默认关闭的状态 - return !is_null($conf) ? $conf->toArray() : ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0); - } /** * 获取设备最新登录微信的 wechatId @@ -102,55 +79,6 @@ class GetDeviceDetailV1Controller extends BaseController ->value('wechatId'); } - /** - * 统计设备登录微信的好友 - * - * @param int $deviceId - * @return int - * @throws \Exception - */ - protected function getTotalFriend(int $deviceId): int - { - $ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId); - - if ($ownerWechatId) { - return WechatFriendShipModel::where( - [ - 'companyId' => $this->getUserInfo('companyId'), - 'ownerWechatId' => $ownerWechatId - ] - ) - ->count(); - } - - return 0; - } - - /** - * 获取设备绑定微信的消息总数 - * - * @param int $deviceId - * @return int - */ - protected function getThirtyDayMsgCount(int $deviceId): int - { - $ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId); - - if ($ownerWechatId) { - $activity = (string)WechatCustomerModel::where( - [ - 'wechatId' => $ownerWechatId, - 'companyId' => $this->getUserInfo('companyId') - ] - ) - ->value('activity'); - - return json_decode($activity)->totalMsgCount ?? 0; - } - - return 0; - } - /** * 获取设备详情 * @param int $id 设备ID @@ -170,11 +98,6 @@ class GetDeviceDetailV1Controller extends BaseController } $device['battery'] = $this->parseExtraForBattery($device['extra']); - $device['features'] = $this->getTaskConfig($id); - $device['totalFriend'] = $this->getTotalFriend($id); - $device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount($id); - - // 设备最后活跃时间为设备状态更新时间 $device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']); // 删除冗余字段 diff --git a/Server/application/cunkebao/controller/device/GetDeviceTaskConfigV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceTaskConfigV1Controller.php new file mode 100644 index 00000000..5cacb6a7 --- /dev/null +++ b/Server/application/cunkebao/controller/device/GetDeviceTaskConfigV1Controller.php @@ -0,0 +1,85 @@ + $deviceId, + 'userId' => $this->getUserInfo('id'), + 'companyId' => $this->getUserInfo('companyId') + ] + ) + ->count() > 0; + + if (!$hasPermission) { + throw new \Exception('您没有权限查看该设备', 403); + } + } + + /** + * 解析taskConfig字段获取功能开关 + * + * @param int $deviceId + * @return int[] + * @throws \Exception + */ + protected function getTaskConfig(int $deviceId): array + { + $conf = DeviceTaskconfModel::alias('c') + ->field([ + 'c.autoAddFriend', 'c.autoReply', 'c.momentsSync', 'c.aiChat' + ]) + ->where( + [ + 'companyId' => $this->getUserInfo('companyId'), + 'deviceId' => $deviceId + ] + ) + ->find(); + + // 未配置时赋予默认关闭的状态 + return !is_null($conf) ? $conf->toArray() : ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0); + } + + /** + * 获取设备详情 + * + * @return \think\response\Json + */ + public function index() + { + try { + $id = $this->request->param('id/d'); + + if ($this->getUserInfo('isAdmin') != UserModel::ADMIN_STP) { + $this->checkUserDevicePermission($id); + } + + return ResponseHelper::success( + $this->getTaskConfig($id) + ); + } catch (\Exception $e) { + return ResponseHelper::error($e->getMessage(), $e->getCode()); + } + } +} \ No newline at end of file