项目管理列表增加设备数量字段

This commit is contained in:
柳清爽
2025-04-21 14:13:32 +08:00
parent 3126efc00d
commit 8d8283c4fd
2 changed files with 33 additions and 6 deletions

View File

@@ -3,8 +3,10 @@
namespace app\superadmin\controller\company;
use app\common\model\Company as CompanyModel;
use app\common\model\Device as DeviceModel;
use app\common\model\User as usersModel;
use app\superadmin\controller\BaseController;
use Eison\Utils\Helper\ArrHelper;
/**
* 公司控制器
@@ -29,6 +31,20 @@ class GetCompanyListController extends BaseController
return array_merge($params, $where);
}
/**
* 获取设备统计
*
* @return array
*/
protected function getDevices()
{
$devices = DeviceModel::field('companyId, count(id) as numCount')->group('companyId')->select();
$devices = $devices ? $devices->toArray() : array();
return ArrHelper::columnTokey('companyId', $devices);
}
/**
* 获取项目列表
*
@@ -71,15 +87,18 @@ class GetCompanyListController extends BaseController
/**
* 构建返回数据
*
* @param \think\Paginator $list
* @param \think\Paginator $Companylist
* @return array
*/
protected function makeReturnedResult(\think\Paginator $list): array
protected function makeReturnedResult(\think\Paginator $Companylist): array
{
$result = [];
$devices = $this->getDevices();
foreach ($Companylist->items() as $item) {
foreach ($list->items() as $item) {
$item->userCount = $this->countUserInCompany($item->companyId);
$item->deviceCount = $devices[$item->companyId]['numCount'] ?? 0;
array_push($result, $item->toArray());
}

View File

@@ -16,6 +16,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { Badge } from "@/components/ui/badge"
interface Project {
id: number
@@ -26,6 +27,7 @@ interface Project {
memo: string | null
userCount: number
createTime: string
deviceCount: number
}
export default function ProjectsPage() {
@@ -138,8 +140,9 @@ export default function ProjectsPage() {
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-center"></TableHead>
<TableHead className="text-center"></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
@@ -154,8 +157,13 @@ export default function ProjectsPage() {
projects.map((project) => (
<TableRow key={project.id}>
<TableCell className="font-medium">{project.name}</TableCell>
<TableCell>{project.status === 1 ? '启用' : '禁用'}</TableCell>
<TableCell>
<Badge variant={project.status === 1 ? "default" : "secondary"}>
{project.status === 1 ? "启用" : "禁用"}
</Badge>
</TableCell>
<TableCell className="text-center">{project.userCount}</TableCell>
<TableCell className="text-center">{project.deviceCount}</TableCell>
<TableCell className="text-center">{project.createTime}</TableCell>
<TableCell className="text-right">
<DropdownMenu>