项目管理列表增加设备数量字段
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user