diff --git a/admin/src/config/index.ts b/admin/src/config/index.ts index 10bbb3da..4bf4e940 100644 --- a/admin/src/config/index.ts +++ b/admin/src/config/index.ts @@ -2,8 +2,8 @@ const config = { terminal: 1, //终端 title: '后台管理系统', //网站默认标题 version: '1.6.0', //版本号 - baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名 - // baseUrl: 'http://127.0.0.1:30005/', + // baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名 + baseUrl: 'http://127.0.0.1:30005/', urlPrefix: 'adminapi', //请求默认前缀 timeout: 10 * 1000 //请求超时时长 } diff --git a/app/adminapi/controller/BaseAdminController.php b/app/adminapi/controller/BaseAdminController.php index db1bbe17..66e8ccea 100644 --- a/app/adminapi/controller/BaseAdminController.php +++ b/app/adminapi/controller/BaseAdminController.php @@ -34,7 +34,6 @@ class BaseAdminController extends BaseLikeAdminController if (isset($this->request->adminInfo) && $this->request->adminInfo) { $this->adminInfo = $this->request->adminInfo; $this->adminId = $this->request->adminInfo['admin_id']; - $this->userId = $this->request->adminInfo['user_id']; } } diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php index 34db92bf..d66db9e1 100644 --- a/app/adminapi/controller/device/DeviceController.php +++ b/app/adminapi/controller/device/DeviceController.php @@ -16,9 +16,9 @@ namespace app\adminapi\controller\device; -use app\adminapi\controller\BaseAdminController; -use app\adminapi\lists\device\DeviceLists; -use app\adminapi\logic\device\DeviceLogic; +use app\adminapi\controller\BaseAdminController; +use app\adminapi\lists\device\DeviceLists; +use app\adminapi\logic\device\DeviceLogic; use app\adminapi\validate\device\DeviceValidate; diff --git a/app/adminapi/lists/device/AirMonitorLists.php b/app/adminapi/lists/device/AirMonitorLists.php index 1a450659..12923c99 100644 --- a/app/adminapi/lists/device/AirMonitorLists.php +++ b/app/adminapi/lists/device/AirMonitorLists.php @@ -44,6 +44,19 @@ class AirMonitorLists extends BaseAdminDataLists implements ListsSearchInterface return array_intersect(array_keys($this->params), $allowSearch); } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -56,7 +69,7 @@ class AirMonitorLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return AirMonitor::withSearch($this->setSearch(), $this->params)->with('device') + return AirMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->with('device') ->field(['id', 'device_id', 'wind_direction', 'wind_speed', 'temperature', 'moisture', 'co2_content', 'pressure', 'rainfall', 'light_intensity', 'create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -73,7 +86,7 @@ class AirMonitorLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return AirMonitor::withSearch($this->setSearch(), $this->params)->count(); + return AirMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/device/DeviceLists.php b/app/adminapi/lists/device/DeviceLists.php index a11baa6a..18433bb0 100644 --- a/app/adminapi/lists/device/DeviceLists.php +++ b/app/adminapi/lists/device/DeviceLists.php @@ -45,6 +45,19 @@ class DeviceLists extends BaseAdminDataLists implements ListsSearchInterface ]; } + public function userSearch(): array + { + $userWhere['d.user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['d.user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -57,11 +70,11 @@ class DeviceLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Db::name('device')->where($this->searchWhere) - ->alias('d') - ->leftJoin('land_device ld','ld.device_id = d.id') - ->leftJoin('land l','l.id = ld.land_id') - ->field('d.*, ld.land_id, l.title') + return Db::name('device')->alias('d') + ->where($this->searchWhere)->where($this->userSearch()) + // ->leftJoin('land_device ld','ld.device_id = d.id') + // ->leftJoin('land l','l.id = ld.land_id') + // ->field('d.*, ld.land_id, l.title') ->limit($this->limitOffset, $this->limitLength) ->order(['d.id' => 'desc']) ->select() @@ -77,7 +90,7 @@ class DeviceLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return Db::name('device')->where($this->searchWhere)->alias('d')->count(); + return Db::name('device')->alias('d')->where($this->searchWhere)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/device/MonitorAlarmLists.php b/app/adminapi/lists/device/MonitorAlarmLists.php index b5fcfd6a..e97b40b3 100644 --- a/app/adminapi/lists/device/MonitorAlarmLists.php +++ b/app/adminapi/lists/device/MonitorAlarmLists.php @@ -47,6 +47,19 @@ class MonitorAlarmLists extends BaseAdminDataLists implements ListsSearchInterfa return array_intersect(array_keys($this->params), $allowSearch); } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -59,7 +72,7 @@ class MonitorAlarmLists extends BaseAdminDataLists implements ListsSearchInterfa */ public function lists(): array { - return MonitorAlarm::withSearch($this->setSearch(), $this->params)->with('device') + return MonitorAlarm::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->with('device') ->field(['id', 'device_id', 'type', 'content', 'value', 'solution', 'create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -76,7 +89,7 @@ class MonitorAlarmLists extends BaseAdminDataLists implements ListsSearchInterfa */ public function count(): int { - return MonitorAlarm::withSearch($this->setSearch(), $this->params)->count(); + return MonitorAlarm::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/device/SoilMonitorLists.php b/app/adminapi/lists/device/SoilMonitorLists.php index 544dafa9..8dc958e8 100644 --- a/app/adminapi/lists/device/SoilMonitorLists.php +++ b/app/adminapi/lists/device/SoilMonitorLists.php @@ -44,6 +44,19 @@ class SoilMonitorLists extends BaseAdminDataLists implements ListsSearchInterfac return array_intersect(array_keys($this->params), $allowSearch); } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -56,7 +69,7 @@ class SoilMonitorLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function lists(): array { - return SoilMonitor::withSearch($this->setSearch(), $this->params)->with('device') + return SoilMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->with('device') ->field(['id', 'device_id', 'temperature', 'moisture', 'conductivity', 'ph', 'n_content', 'p_content', 'k_content', 'create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -73,7 +86,7 @@ class SoilMonitorLists extends BaseAdminDataLists implements ListsSearchInterfac */ public function count(): int { - return SoilMonitor::withSearch($this->setSearch(), $this->params)->count(); + return SoilMonitor::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/land/LandLists.php b/app/adminapi/lists/land/LandLists.php index 8b5a3835..b21d591f 100644 --- a/app/adminapi/lists/land/LandLists.php +++ b/app/adminapi/lists/land/LandLists.php @@ -43,6 +43,19 @@ class LandLists extends BaseAdminDataLists implements ListsSearchInterface ]; } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -55,7 +68,7 @@ class LandLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Land::where($this->searchWhere)->with('user') + return Land::where($this->searchWhere)->where($this->userSearch())->with('user') ->field(['id', 'user_id', 'title', 'total_area', 'residual_area', 'province_code', 'province_name', 'city_code', 'city_name', 'county_code', 'county_name', 'town_code', 'town_name', 'village_code', 'village_name', 'group_code', 'group_name', 'longitude', 'latitude', 'master_name', 'master_phone']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -72,7 +85,7 @@ class LandLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return Land::where($this->searchWhere)->count(); + return Land::where($this->searchWhere)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/land/LandPlantActionLists.php b/app/adminapi/lists/land/LandPlantActionLists.php index cdebc64f..e4dd2bba 100644 --- a/app/adminapi/lists/land/LandPlantActionLists.php +++ b/app/adminapi/lists/land/LandPlantActionLists.php @@ -42,6 +42,19 @@ class LandPlantActionLists extends BaseAdminDataLists implements ListsSearchInte ]; } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -54,7 +67,7 @@ class LandPlantActionLists extends BaseAdminDataLists implements ListsSearchInte */ public function lists(): array { - return LandPlantAction::where($this->searchWhere)->with('landPlant') + return LandPlantAction::where($this->searchWhere)->where($this->userSearch())->with('landPlant') ->field(['id', 'plant_id', 'type', 'type_text', 'detail']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -71,7 +84,7 @@ class LandPlantActionLists extends BaseAdminDataLists implements ListsSearchInte */ public function count(): int { - return LandPlantAction::where($this->searchWhere)->count(); + return LandPlantAction::where($this->searchWhere)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/land/LandPlantLists.php b/app/adminapi/lists/land/LandPlantLists.php index 212daad1..c583ee35 100644 --- a/app/adminapi/lists/land/LandPlantLists.php +++ b/app/adminapi/lists/land/LandPlantLists.php @@ -57,6 +57,19 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface return $where; } + public function userSearch(): array + { + $userWhere['user_id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['user_id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['user_id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } /** * @notes 获取列表 @@ -69,7 +82,7 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return LandPlant::where($this->queryWhere())->where($this->searchWhere)->with('land') + return LandPlant::where($this->queryWhere())->where($this->searchWhere)->where($this->userSearch())->with('land') ->field(['id', 'land_id', 'kind', 'breed', 'area', 'user', 'status', 'pic', 'qr_code', 'plant_date', 'remark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) @@ -86,7 +99,7 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return LandPlant::where($this->queryWhere())->where($this->searchWhere)->count(); + return LandPlant::where($this->queryWhere())->where($this->searchWhere)->where($this->userSearch())->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/user/UserLists.php b/app/adminapi/lists/user/UserLists.php index 493babd0..af2b6354 100644 --- a/app/adminapi/lists/user/UserLists.php +++ b/app/adminapi/lists/user/UserLists.php @@ -39,6 +39,20 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface return array_intersect(array_keys($this->params), $allowSearch); } + public function userSearch(): array + { + $userWhere['id'] = 0; + // 超级管理员数据 + if ($this->adminInfo['root'] && !$this->adminInfo['user_id']) { + unset($userWhere['id']); + } + // 普通用户数据 + if (!$this->adminInfo['root'] && $this->adminInfo['user_id']) { + $userWhere['id'] = $this->adminInfo['user_id']; + } + return $userWhere; + } + /** * @notes 获取用户列表 * @return array @@ -51,7 +65,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface public function lists(): array { $field = "id,sn,nickname,sex,avatar,account,mobile,channel,is_disable,create_time"; - $lists = User::withSearch($this->setSearch(), $this->params) + $lists = User::withSearch($this->setSearch(), $this->params)->where($this->userSearch()) ->limit($this->limitOffset, $this->limitLength) ->field($field) ->order('id desc') @@ -73,7 +87,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function count(): int { - return User::withSearch($this->setSearch(), $this->params)->count(); + return User::withSearch($this->setSearch(), $this->params)->where($this->userSearch())->count(); }