超管后台 - 对接关联设备 至后台

This commit is contained in:
柳清爽
2025-04-23 16:47:02 +08:00
parent 419d5b42a0
commit 938e865b0a
2 changed files with 51 additions and 7 deletions

View File

@@ -23,7 +23,7 @@ class GetCompanyDevicesForProfileController extends Controller
{
$companyId = $this->request->param('companyId/d', 0);
$devices = DeviceModel::where(compact('companyId'))->field('id,memo,phone,model,brand,alive,id deviceId')
$devices = DeviceModel::where(compact('companyId'))->field('id,memo,imei,phone,model,brand,alive,id deviceId')
->select()
->toArray();

View File

@@ -24,10 +24,25 @@ interface ProjectProfile {
userCount: number
}
interface Device {
id: number
memo: string
phone: string
model: string
brand: string
alive: number
deviceId: number
wechatId: string
friendCount: number
wAlive: number
imei: string
}
export default function ProjectDetailPage({ params }: { params: { id: string } }) {
const router = useRouter()
const [isLoading, setIsLoading] = useState(true)
const [profile, setProfile] = useState<ProjectProfile | null>(null)
const [devices, setDevices] = useState<Device[]>([])
const [activeTab, setActiveTab] = useState("overview")
const { id } = use(params)
@@ -52,6 +67,27 @@ export default function ProjectDetailPage({ params }: { params: { id: string } }
fetchProjectProfile()
}, [id])
useEffect(() => {
const fetchDevices = async () => {
if (activeTab === "devices") {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/devices?companyId=${id}`)
const data = await response.json()
if (data.code === 200) {
setDevices(data.data)
} else {
toast.error(data.msg || "获取设备列表失败")
}
} catch (error) {
toast.error("网络错误,请稍后重试")
}
}
}
fetchDevices()
}, [activeTab, id])
if (isLoading) {
return <div className="flex items-center justify-center min-h-screen">...</div>
}
@@ -155,18 +191,26 @@ export default function ProjectDetailPage({ params }: { params: { id: string } }
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead>IMEI</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{/* Assuming devices are fetched from the profile */}
{/* Replace with actual devices data */}
{/* {profile.devices.map((device) => (
{devices.map((device) => (
<TableRow key={device.id}>
<TableCell className="font-medium">{device.name}</TableCell>
<TableCell className="text-right">{device.wechatFriends}</TableCell>
<TableCell className="font-medium">{device.memo}</TableCell>
<TableCell>{device.model}</TableCell>
<TableCell>{device.brand}</TableCell>
<TableCell>{device.imei}</TableCell>
<TableCell>{device.alive === 1 ? "在线" : "离线"}</TableCell>
<TableCell>{device.wAlive === 1 ? "在线" : device.wAlive === 0 ? "离线" : "未登录微信"}</TableCell>
<TableCell className="text-right">{device.friendCount || 0}</TableCell>
</TableRow>
))} */}
))}
</TableBody>
</Table>
</CardContent>