diff --git a/admin/src/api/device.ts b/admin/src/api/device.ts new file mode 100644 index 00000000..4c5f73cd --- /dev/null +++ b/admin/src/api/device.ts @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 监测设备列表 +export function apiDeviceLists(params: any) { + return request.get({ url: '/device.device/lists', params }) +} + +// 添加监测设备 +export function apiDeviceAdd(params: any) { + return request.post({ url: '/device.device/add', params }) +} + +// 编辑监测设备 +export function apiDeviceEdit(params: any) { + return request.post({ url: '/device.device/edit', params }) +} + +// 删除监测设备 +export function apiDeviceDelete(params: any) { + return request.post({ url: '/device.device/delete', params }) +} + +// 监测设备详情 +export function apiDeviceDetail(params: any) { + return request.get({ url: '/device.device/detail', params }) +} \ No newline at end of file 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/admin/src/views/device/edit.vue b/admin/src/views/device/edit.vue new file mode 100644 index 00000000..83bba4bb --- /dev/null +++ b/admin/src/views/device/edit.vue @@ -0,0 +1,182 @@ + + + diff --git a/admin/src/views/device/index.vue b/admin/src/views/device/index.vue new file mode 100644 index 00000000..83562a08 --- /dev/null +++ b/admin/src/views/device/index.vue @@ -0,0 +1,186 @@ + + + + diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php new file mode 100644 index 00000000..34db92bf --- /dev/null +++ b/app/adminapi/controller/device/DeviceController.php @@ -0,0 +1,108 @@ +dataLists(new DeviceLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function add() + { + $params = (new DeviceValidate())->post()->goCheck('add'); + $result = DeviceLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(DeviceLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function edit() + { + $params = (new DeviceValidate())->post()->goCheck('edit'); + $result = DeviceLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(DeviceLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function delete() + { + $params = (new DeviceValidate())->post()->goCheck('delete'); + DeviceLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function detail() + { + $params = (new DeviceValidate())->goCheck('detail'); + $result = DeviceLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/device/DeviceLists.php b/app/adminapi/lists/device/DeviceLists.php new file mode 100644 index 00000000..51dfb710 --- /dev/null +++ b/app/adminapi/lists/device/DeviceLists.php @@ -0,0 +1,79 @@ + ['code', 'name', 'type', 'status', 'is_online', 'is_bind'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function lists(): array + { + return Device::where($this->searchWhere) + ->field(['id', 'code', 'name', 'type', 'status', 'is_online', 'is_bind']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function count(): int + { + return Device::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/device/DeviceLogic.php b/app/adminapi/logic/device/DeviceLogic.php new file mode 100644 index 00000000..1ba9a53e --- /dev/null +++ b/app/adminapi/logic/device/DeviceLogic.php @@ -0,0 +1,116 @@ + $params['code'], + 'name' => $params['name'], + 'type' => $params['type'], + 'status' => $params['status'], + 'is_online' => $params['is_online'], + 'is_bind' => $params['is_bind'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Device::where('id', $params['id'])->update([ + 'code' => $params['code'], + 'name' => $params['name'], + 'type' => $params['type'], + 'status' => $params['status'], + 'is_online' => $params['is_online'], + 'is_bind' => $params['is_bind'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public static function delete(array $params): bool + { + return Device::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public static function detail($params): array + { + return Device::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/device/DeviceValidate.php b/app/adminapi/validate/device/DeviceValidate.php new file mode 100644 index 00000000..4e2a8a43 --- /dev/null +++ b/app/adminapi/validate/device/DeviceValidate.php @@ -0,0 +1,106 @@ + 'require', + 'code' => 'require', + 'name' => 'require', + 'type' => 'require', + 'status' => 'require', + 'is_online' => 'require', + 'is_bind' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'code' => '设备编码', + 'name' => '设备名称', + 'type' => '设备类型', + 'status' => '设备状态', + 'is_online' => '是否在线', + 'is_bind' => '是否绑定土地', + ]; + + + /** + * @notes 添加场景 + * @return DeviceValidate + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function sceneAdd() + { + return $this->only(['code','name','type','status','is_online','is_bind']); + } + + + /** + * @notes 编辑场景 + * @return DeviceValidate + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function sceneEdit() + { + return $this->only(['id','code','name','type','status','is_online','is_bind']); + } + + + /** + * @notes 删除场景 + * @return DeviceValidate + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return DeviceValidate + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/device/Device.php b/app/common/model/device/Device.php new file mode 100644 index 00000000..5f5eae8b --- /dev/null +++ b/app/common/model/device/Device.php @@ -0,0 +1,38 @@ +hasOne(\app\common\model\land\Land::class, 'id', 'land_id'); - } + } } \ No newline at end of file