feat(iot):优化 IoT 请求的代码风格(device 界面调整引入)

pull/345/head
YunaiV 2026-05-18 12:26:58 +08:00
parent d649a617ac
commit 5182cdbffa
7 changed files with 25 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { IotDeviceApi } from '#/api/iot/device/device';
import type { IotProductApi } from '#/api/iot/product/product';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
@ -34,7 +34,7 @@ const loading = ref(true);
const product = ref<IotProductApi.Product>({} as IotProductApi.Product);
const device = ref<IotDeviceApi.Device>({} as IotDeviceApi.Device);
const activeTab = ref('info');
const thingModelList = ref<ThingModelData[]>([]);
const thingModelList = ref<ThingModelApi.ThingModel[]>([]);
/** 获取设备详情 */
async function getDeviceData(deviceId: number) {
@ -113,11 +113,11 @@ onMounted(async () => {
</Tabs.TabPane>
<Tabs.TabPane
v-if="product.deviceType === DeviceTypeEnum.GATEWAY"
key="sub-device"
key="subDevice"
tab="子设备管理"
>
<DeviceDetailsSubDevice
v-if="activeTab === 'sub-device' && device.id"
v-if="activeTab === 'subDevice' && device.id"
:device-id="device.id"
/>
</Tabs.TabPane>

View File

@ -6,7 +6,7 @@ import type { IotDeviceApi } from '#/api/iot/device/device';
import type { IotDeviceModbusConfigApi } from '#/api/iot/device/modbus/config';
import type { IotDeviceModbusPointApi } from '#/api/iot/device/modbus/point';
import type { IotProductApi } from '#/api/iot/product/product';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import type { DescriptionItemSchema } from '#/components/description';
import { computed, h, onMounted, ref } from 'vue';
@ -35,7 +35,7 @@ defineOptions({ name: 'DeviceModbusConfig' });
const props = defineProps<{
device: IotDeviceApi.Device;
product: IotProductApi.Product;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
// ======================= =======================

View File

@ -2,7 +2,7 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '#/adapter/form';
import type { IotDeviceModbusPointApi } from '#/api/iot/device/modbus/point';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { computed, h, ref } from 'vue';
@ -35,7 +35,7 @@ const getTitle = computed(() => {
return formData.value?.id ? '编辑点位' : '新增点位';
});
const deviceId = ref<number>(0);
const thingModelList = ref<ThingModelData[]>([]);
const thingModelList = ref<ThingModelApi.ThingModel[]>([]);
/** 筛选属性类型的物模型 */
const propertyList = computed(() => {
@ -289,7 +289,7 @@ const [Modal, modalApi] = useVbenModal({
const data = modalApi.getData<{
deviceId: number;
id?: number;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
if (!data) {
return;

View File

@ -4,7 +4,7 @@ import type { TableColumnType } from 'ant-design-vue';
import type { IotDeviceApi } from '#/api/iot/device/device';
import type { IotProductApi } from '#/api/iot/product/product';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { computed, ref } from 'vue';
@ -36,7 +36,7 @@ import DeviceDetailsMessage from './message.vue';
const props = defineProps<{
device: IotDeviceApi.Device;
product: IotProductApi.Product;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
//
@ -224,7 +224,7 @@ async function handlePropertyPost() {
}
//
async function handleEventPost(row: ThingModelData) {
async function handleEventPost(row: ThingModelApi.ThingModel) {
try {
const valueStr = formData.value[row.identifier!];
let params: any = {};
@ -306,7 +306,7 @@ async function handlePropertySet() {
}
//
async function handleServiceInvoke(row: ThingModelData) {
async function handleServiceInvoke(row: ThingModelApi.ThingModel) {
try {
const valueStr = formData.value[row.identifier!];
let params: any = {};

View File

@ -1,7 +1,7 @@
<!-- 设备事件管理 -->
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { computed, onMounted, reactive, watch } from 'vue';
@ -21,7 +21,7 @@ import {
const props = defineProps<{
deviceId: number;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
/** 查询参数 */
@ -33,7 +33,7 @@ const queryParams = reactive({
/** 事件类型的物模型数据 */
const eventThingModels = computed(() => {
return props.thingModelList.filter(
(item: ThingModelData) =>
(item: ThingModelApi.ThingModel) =>
String(item.type) === String(IoTThingModelTypeEnum.EVENT),
);
});
@ -123,7 +123,7 @@ function resetQuery() {
function getEventName(identifier: string | undefined) {
if (!identifier) return '-';
const event = eventThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
(item: ThingModelApi.ThingModel) => item.identifier === identifier,
);
return event?.name || identifier;
}
@ -132,7 +132,7 @@ function getEventName(identifier: string | undefined) {
function getEventType(identifier: string | undefined) {
if (!identifier) return '-';
const event = eventThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
(item: ThingModelApi.ThingModel) => item.identifier === identifier,
);
if (!event?.event?.type) return '-';
return getEventTypeLabel(event.event.type) || '-';

View File

@ -1,7 +1,7 @@
<!-- 设备服务调用 -->
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { computed, onMounted, reactive, watch } from 'vue';
@ -21,7 +21,7 @@ import {
const props = defineProps<{
deviceId: number;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
/** 查询参数 */
@ -33,7 +33,7 @@ const queryParams = reactive({
/** 服务类型的物模型数据 */
const serviceThingModels = computed(() => {
return props.thingModelList.filter(
(item: ThingModelData) =>
(item: ThingModelApi.ThingModel) =>
String(item.type) === String(IoTThingModelTypeEnum.SERVICE),
);
});
@ -136,7 +136,7 @@ function resetQuery() {
function getServiceName(identifier: string | undefined) {
if (!identifier) return '-';
const service = serviceThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
(item: ThingModelApi.ThingModel) => item.identifier === identifier,
);
return service?.name || identifier;
}
@ -145,7 +145,7 @@ function getServiceName(identifier: string | undefined) {
function getCallType(identifier: string | undefined) {
if (!identifier) return '-';
const service = serviceThingModels.value.find(
(item: ThingModelData) => item.identifier === identifier,
(item: ThingModelApi.ThingModel) => item.identifier === identifier,
);
if (!service?.service?.callType) return '-';
return getThingModelServiceCallTypeLabel(service.service.callType) || '-';

View File

@ -1,6 +1,6 @@
<!-- 设备物模型设备属性事件管理服务调用 -->
<script lang="ts" setup>
import type { ThingModelData } from '#/api/iot/thingmodel';
import type { ThingModelApi } from '#/api/iot/thingmodel';
import { ref } from 'vue';
@ -14,7 +14,7 @@ import DeviceDetailsThingModelService from './thing-model-service.vue';
const props = defineProps<{
deviceId: number;
thingModelList: ThingModelData[];
thingModelList: ThingModelApi.ThingModel[];
}>();
const activeTab = ref('property'); //