From f8c263ed6e863c8afc27d48ea9ce5d3ddc6914b8 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Wed, 29 Nov 2023 15:30:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=BE=E5=A4=87=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/package-lock.json | 18 +- admin/package.json | 2 +- admin/src/api/device.ts | 5 + admin/src/views/device/detail.vue | 470 +++++++----------- admin/src/views/device/edit.vue | 1 - admin/yarn.lock | 10 +- .../controller/device/DeviceController.php | 12 + app/adminapi/logic/device/DeviceLogic.php | 52 +- .../validate/device/DeviceValidate.php | 12 + 9 files changed, 287 insertions(+), 295 deletions(-) diff --git a/admin/package-lock.json b/admin/package-lock.json index e5a768cf..c838125c 100644 --- a/admin/package-lock.json +++ b/admin/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "license": "MIT", "dependencies": { - "@element-plus/icons-vue": "^2.0.6", + "@element-plus/icons-vue": "^2.3.1", "@highlightjs/vue-plugin": "^2.1.0", "@wangeditor/editor": "^5.1.12", "@wangeditor/editor-for-vue": "^5.1.12", @@ -564,9 +564,12 @@ } }, "node_modules/@element-plus/icons-vue": { - "version": "2.0.6", - "resolved": "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.6.tgz", - "integrity": "sha512-lPpG8hYkjL/Z97DH5Ei6w6o22Z4YdNglWCNYOPcB33JCF2A4wye6HFgSI7hEt9zdLyxlSpiqtgf9XcYU+m5mew==" + "version": "2.3.1", + "resolved": "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.3.1.tgz", + "integrity": "sha512-XxVUZv48RZAd87ucGS48jPf6pKu0yV5UCg9f4FFwtrYxXOwWuVJo6wOvSLKEoMQKjv8GsX/mhP6UsC1lRwbUWg==", + "peerDependencies": { + "vue": "^3.2.0" + } }, "node_modules/@esbuild/linux-loong64": { "version": "0.14.53", @@ -7790,9 +7793,10 @@ "integrity": "sha512-ej5oVy6lykXsvieQtqZxCOaLT+xD4+QNarq78cIYISHmZXshCvROLudpQN3lfL8G0NL7plMSSK+zlyvCaIJ4Iw==" }, "@element-plus/icons-vue": { - "version": "2.0.6", - "resolved": "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.6.tgz", - "integrity": "sha512-lPpG8hYkjL/Z97DH5Ei6w6o22Z4YdNglWCNYOPcB33JCF2A4wye6HFgSI7hEt9zdLyxlSpiqtgf9XcYU+m5mew==" + "version": "2.3.1", + "resolved": "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.3.1.tgz", + "integrity": "sha512-XxVUZv48RZAd87ucGS48jPf6pKu0yV5UCg9f4FFwtrYxXOwWuVJo6wOvSLKEoMQKjv8GsX/mhP6UsC1lRwbUWg==", + "requires": {} }, "@esbuild/linux-loong64": { "version": "0.14.53", diff --git a/admin/package.json b/admin/package.json index c6c68cf3..76f56580 100644 --- a/admin/package.json +++ b/admin/package.json @@ -10,7 +10,7 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { - "@element-plus/icons-vue": "^2.0.6", + "@element-plus/icons-vue": "^2.3.1", "@highlightjs/vue-plugin": "^2.1.0", "@wangeditor/editor": "^5.1.12", "@wangeditor/editor-for-vue": "^5.1.12", diff --git a/admin/src/api/device.ts b/admin/src/api/device.ts index 69b6be39..d5ea49de 100644 --- a/admin/src/api/device.ts +++ b/admin/src/api/device.ts @@ -33,4 +33,9 @@ export function apiDeviceDelete(params: any) { // 监测设备详情 export function apiDeviceDetail(params: any) { return request.get({ url: '/device.device/detail', params }) +} + +// 设备监控数据 +export function apiDeviceMonitorData(params: any) { + return request.get({ url: '/device.device/monitorData', params }) } \ No newline at end of file diff --git a/admin/src/views/device/detail.vue b/admin/src/views/device/detail.vue index fd652136..a678503b 100644 --- a/admin/src/views/device/detail.vue +++ b/admin/src/views/device/detail.vue @@ -1,294 +1,206 @@ - + +const handleClick = (id: any, type: any) => { + monitorData.gridData = [{}] + queryMonitorData.device_id = id + queryMonitorData.monitor_type = type + apiDeviceMonitorData({ + id: id, + monitor_type: type, + page_no: queryMonitorData.page_no, + page_size: queryMonitorData.page_size + }) + .then((res: any) => { + dialogTableVisible.value = true + queryMonitorData.total = res.count + res.lists.map((data: any) => { + queryMonitorData.total = res.count + monitorData.gridData.push({ + id: data.id, + date: data.create_time + ? timeFormat(data.create_time, 'yyyy-mm-dd hh:MM:ss') + : '', + value: data.monitor_value + }) + }) + }) + .catch((err: any) => { + console.log('err', err) + }) +} + +const handleCurrentChange = (val: number) => { + console.log(`current page: ${val}`) + monitorData.gridData = [{}] + apiDeviceMonitorData({ + id: queryMonitorData.device_id, + monitor_type: queryMonitorData.monitor_type, + page_no: val, + page_size: queryMonitorData.page_size + }) + .then((res: any) => { + dialogTableVisible.value = true + queryMonitorData.total = res.count + res.lists.map((data: any) => { + monitorData.gridData.push({ + id: data.id, + date: data.create_time + ? timeFormat(data.create_time, 'yyyy-mm-dd hh:MM:ss') + : '', + value: data.monitor_value + }) + }) + }) + .catch((err: any) => { + console.log('err', err) + }) +} + \ No newline at end of file diff --git a/admin/src/views/device/edit.vue b/admin/src/views/device/edit.vue index fd652136..b503fa87 100644 --- a/admin/src/views/device/edit.vue +++ b/admin/src/views/device/edit.vue @@ -202,7 +202,6 @@ const setFormData = async (data: Record) => { formData[key] = data[key] } } - console.log(dictData.monitor_item) } interface ListItem { diff --git a/admin/yarn.lock b/admin/yarn.lock index 9bbde146..69382446 100644 --- a/admin/yarn.lock +++ b/admin/yarn.lock @@ -291,10 +291,10 @@ resolved "https://registry.npmmirror.com/@ctrl/tinycolor/-/tinycolor-3.4.1.tgz" integrity sha512-ej5oVy6lykXsvieQtqZxCOaLT+xD4+QNarq78cIYISHmZXshCvROLudpQN3lfL8G0NL7plMSSK+zlyvCaIJ4Iw== -"@element-plus/icons-vue@^2.0.6": - version "2.0.6" - resolved "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.6.tgz" - integrity sha512-lPpG8hYkjL/Z97DH5Ei6w6o22Z4YdNglWCNYOPcB33JCF2A4wye6HFgSI7hEt9zdLyxlSpiqtgf9XcYU+m5mew== +"@element-plus/icons-vue@^2.0.6", "@element-plus/icons-vue@^2.3.1": + version "2.3.1" + resolved "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.3.1.tgz" + integrity sha512-XxVUZv48RZAd87ucGS48jPf6pKu0yV5UCg9f4FFwtrYxXOwWuVJo6wOvSLKEoMQKjv8GsX/mhP6UsC1lRwbUWg== "@eslint/eslintrc@^1.3.0": version "1.3.0" @@ -4293,7 +4293,7 @@ vue-tsc@^0.38.1: dependencies: "@volar/vue-typescript" "0.38.9" -vue@^3.2.2, vue@^3.2.37: +vue@^3.2.0, vue@^3.2.2, vue@^3.2.37: version "3.2.37" resolved "https://registry.npmmirror.com/vue/-/vue-3.2.37.tgz" integrity sha512-bOKEZxrm8Eh+fveCqS1/NkG/n6aMidsI6hahas7pa0w/l7jkbssJVsRhVDs07IdDq7h9KHswZOgItnwJAgtVtQ== diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php index d66db9e1..0df9d7f0 100644 --- a/app/adminapi/controller/device/DeviceController.php +++ b/app/adminapi/controller/device/DeviceController.php @@ -104,5 +104,17 @@ class DeviceController extends BaseAdminController return $this->data($result); } + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function monitorData() + { + $params = (new DeviceValidate())->goCheck('monitorData'); + $result = DeviceLogic::monitorData($params); + return $this->data($result); + } } \ No newline at end of file diff --git a/app/adminapi/logic/device/DeviceLogic.php b/app/adminapi/logic/device/DeviceLogic.php index 304f46ed..7ffc8055 100644 --- a/app/adminapi/logic/device/DeviceLogic.php +++ b/app/adminapi/logic/device/DeviceLogic.php @@ -17,9 +17,9 @@ namespace app\adminapi\logic\device; use app\common\model\device\Device; use app\common\logic\BaseLogic; +use think\facade\Config; use think\facade\Db; - /** * Device逻辑 * Class DeviceLogic @@ -138,6 +138,54 @@ class DeviceLogic extends BaseLogic */ public static function detail($params): array { - return Device::findOrEmpty($params['id'])->toArray(); + $detail = Db::name('device')->alias('d') + ->where('d.id', $params['id']) + ->leftJoin('user u','u.id = d.user_id') + ->leftJoin('product_device pd','pd.device_id = d.id') + ->leftJoin('product p','p.id = pd.product_id') + ->leftJoin('land_product lp','lp.product_id = pd.product_id') + ->leftJoin('land l','l.id = lp.land_id') + ->field('d.*, u.account, pd.product_id, p.name as product_name, lp.land_id, l.title as land_title') + ->findOrEmpty(); + + $monitorItemArray = []; + if (!empty($detail['monitor_item'])) { + $monitorItemArray = explode(',', $detail['monitor_item']); + } + $dictTypeId = Db::name('dict_type')->where('type', 'monitor_item')->value('id'); + $monitorItemArray = Db::name('dict_data')->where('type_id', $dictTypeId)->whereIn('value', $monitorItemArray)->field(['name', 'value'])->select()->toArray(); + foreach($monitorItemArray as $k=>$v) { + $monitorItemArray[$k]['device_id'] = $params['id']; + $monitorItemArray[$k]['monitor_value'] = '-'; + $monitorItemArray[$k]['last_time'] = '-'; + $monitorData = Db::name('device_monitor_data')->where('device_id', $params['id'])->where('monitor_item', $v['value'])->order(['id' => 'desc'])->find(); + if (!empty($monitorData)) { + $monitorItemArray[$k]['monitor_value'] = $monitorData['monitor_value']; + $monitorItemArray[$k]['last_time'] = date('Y-m-d H:i:s', $monitorData['create_time']); + } + } + $detail['monitor_item'] = $monitorItemArray; + return $detail; + } + + public static function monitorData($params): array + { + $pageSizeMax = Config::get('project.lists.page_size_max'); + $pageSize = Config::get('project.lists.page_size'); + $pageNo = $page_no = request()->get('page_no', 1) ?: 1; + $pageSize = $page_size = request()->get('page_size', $pageSize) ?: $pageSize; + + $limitOffset = ($pageNo - 1) * $pageSize; + $limitLength = $pageSize; + $where['device_id'] = $params['id']; + $where['monitor_item'] = $params['monitor_type']; + $lists = Db::name('device_monitor_data') + ->where($where) + ->limit($limitOffset, $limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + $count = Db::name('device_monitor_data')->where($where)->count(); + return compact('lists', 'count', 'page_no', 'page_size'); } } \ No newline at end of file diff --git a/app/adminapi/validate/device/DeviceValidate.php b/app/adminapi/validate/device/DeviceValidate.php index f200577e..1bd92912 100644 --- a/app/adminapi/validate/device/DeviceValidate.php +++ b/app/adminapi/validate/device/DeviceValidate.php @@ -35,6 +35,7 @@ class DeviceValidate extends BaseValidate 'code' => 'require', 'name' => 'require', 'type' => 'require', + 'monitor_type' => 'require', 'status' => 'require', 'is_online' => 'require', 'is_bind' => 'require', @@ -103,4 +104,15 @@ class DeviceValidate extends BaseValidate return $this->only(['id']); } + /** + * @notes 详情场景 + * @return DeviceValidate + * @author likeadmin + * @date 2023/11/24 15:30 + */ + public function sceneMonitorData() + { + return $this->only(['id', 'monitor_type']); + } + } \ No newline at end of file