From 76d1fc1df78203e1f0c5995b5f89df9d8034a9e4 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 25 Jan 2024 16:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=AF=E6=BA=90=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/api/device.ts | 5 + admin/src/views/device/edit.vue | 97 +++++++++++++++---- .../controller/device/DeviceController.php | 24 +++++ 3 files changed, 108 insertions(+), 18 deletions(-) diff --git a/admin/src/api/device.ts b/admin/src/api/device.ts index c721272..ff0ef0f 100644 --- a/admin/src/api/device.ts +++ b/admin/src/api/device.ts @@ -38,4 +38,9 @@ export function apiDeviceDetail(params: any) { // 设备监控数据 export function apiDeviceMonitorData(params: any) { return request.get({ url: '/device.device/monitorData', params }) +} + +// 设备编码和ICCID +export function apiDeviceIccid(params: any) { + return request.get({ url: '/device.device/queryDeviceIccid', params }) } \ No newline at end of file diff --git a/admin/src/views/device/edit.vue b/admin/src/views/device/edit.vue index 138d1a1..ed13186 100644 --- a/admin/src/views/device/edit.vue +++ b/admin/src/views/device/edit.vue @@ -40,12 +40,39 @@ - - - + + + + + + + + - + + + + + + - - - - - + @@ -112,7 +130,7 @@ import { useDictOptions } from '@/hooks/useDictOptions' import {type FormInstance } from 'element-plus' import Popup from '@/components/popup/index.vue' -import { apiDeviceAdd, apiDeviceEdit, apiDeviceDetail, getUserList, apiProductLists} from '@/api/device' +import {apiDeviceAdd, apiDeviceEdit, apiDeviceDetail, getUserList, apiProductLists, apiDeviceIccid} from '@/api/device' import { timeFormat } from '@/utils/util' import type { PropType } from 'vue' import {ref} from "vue"; @@ -157,7 +175,7 @@ const formData = reactive({ name: '', video_url: '', type: '', - monitor_item: '', + monitor_item: [], status: '', is_online: '', image: '' @@ -191,7 +209,34 @@ const formRules = reactive({ trigger: ['blur'] }], }) +const deviceChange = async (value: string) => { + const temp = await apiDeviceIccid({ + deviceId: value ?? '' + }) + formData.iccid = temp[0]['iccid'] + if ( temp[0]['type'] == 0) { + formData.monitor_item = ['temperature'] + } + if ( temp[0]['type'] == 1) { + formData.monitor_item = ['ambient_temperature','ambient_humidity'] + } + if ( temp[0]['type'] == 2) { + formData.monitor_item = ['nitrogen'] + } + if ( temp[0]['type'] == 3) { + formData.monitor_item = ['methane'] + } + if ( temp[0]['type'] == 4) { + formData.monitor_item = ['noise'] + } + if ( temp[0]['type'] == 5) { + formData.monitor_item = ['fireproof'] + + } + + +} // 获取详情 const setFormData = async (data: Record) => { @@ -204,13 +249,20 @@ const setFormData = async (data: Record) => { } const { optionsData } = useDictOptions<{ - product: any[] + product: any[], + deviceIccids: any[], }>({ product: { api: apiProductLists, params: { all: 1 } + }, + deviceIccids:{ + api: apiDeviceIccid, + params: { + all: 1 + } } }) @@ -225,6 +277,15 @@ const queryProduct = async (query: string) => { loading.value = false } +const queryDeviceIccid = async (query: string) => { + loading.value = true + const deviceList = await apiDeviceIccid({ + deviceId: query ?? '' + }) + optionsData.deviceIccids = deviceList + loading.value = false +} + const getDetail = async (row: Record) => { const data = await apiDeviceDetail({ @@ -260,7 +321,7 @@ const generateUuid = (length: number) => { //打开弹窗 const open = (type = 'add') => { mode.value = type - formData.code = generateUuid(3) + // formData.code = generateUuid(3) popupRef.value?.open() } diff --git a/app/adminapi/controller/device/DeviceController.php b/app/adminapi/controller/device/DeviceController.php index 4cc4ae6..ab05637 100644 --- a/app/adminapi/controller/device/DeviceController.php +++ b/app/adminapi/controller/device/DeviceController.php @@ -20,6 +20,7 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\device\DeviceLists; use app\adminapi\logic\device\DeviceLogic; use app\adminapi\validate\device\DeviceValidate; +use Symfony\Component\HttpClient\HttpClient; /** @@ -122,4 +123,27 @@ class DeviceController extends BaseAdminController return $this->data($result); } + + public function queryDeviceIccid() + { + $iccid = $this->request->param('iccid', ''); + $deviceId = $this->request->param('deviceId', ''); + $requestResponse = HttpClient::create()->request('GET', env('PROJECT.MQTT_PROJECT_URL'). '/api/xumu/device/query', [ + 'query' => ["iccid"=>$iccid, "deviceId"=>$deviceId], + + ]); + $result = json_decode($requestResponse->getContent(), true); + $re = $result['data']['values']; + $datas = []; + $iccidRow = $re[0]; + $typeRow = $re[1]; + $snRow = $re[2]; + foreach ($iccidRow as $key => $value){ + $datas[$key]['iccid'] = $value; + $datas[$key]['device_sn'] = $snRow[$key]; + $datas[$key]['type'] = $typeRow[$key]; + } + return $this->data($datas); + } + } \ No newline at end of file