diff --git a/src/api/device-manage/device/cloud-command.ts b/src/api/device-manage/device/cloud-command.ts index ebe0c129..47d2f2b4 100644 --- a/src/api/device-manage/device/cloud-command.ts +++ b/src/api/device-manage/device/cloud-command.ts @@ -1,4 +1,4 @@ -import type { GetCloudCommandLogsParams } from './types' +import type { CommandToDeviceData, GetCloudCommandLogsParams, MessageToDeviceData } from './types' import { defHttp } from '@/utils/http/axios' export function getCloudCommandLogs(params: GetCloudCommandLogsParams) { @@ -16,3 +16,17 @@ export function getMessageContent(id: string) { }, }) } + +export function sendMessageToDevice(data: MessageToDeviceData) { + return defHttp.post({ + url: '/cloud/sendMessage', + data, + }) +} + +export function sendCommandToDevice(data: CommandToDeviceData) { + return defHttp.post({ + url: '/cloud/sendCommand', + data, + }) +} diff --git a/src/api/device-manage/device/types.ts b/src/api/device-manage/device/types.ts index 1efea4b4..91667704 100644 --- a/src/api/device-manage/device/types.ts +++ b/src/api/device-manage/device/types.ts @@ -25,3 +25,22 @@ export interface DevicePropertie { export interface GetCloudCommandLogsParams extends PageParam { messageType?: number } + +export enum CloudCommandType { + Attribute = 1, + Command = 2, + Message = 3, +} + +export interface MessageToDeviceData { + deviceId: string + topic: string + message: string +} + +export interface CommandToDeviceData { + deviceId: string + modelId: string + itemId: string + value: string | number +} diff --git a/src/api/product/model.ts b/src/api/product/model.ts index 1ba5f178..63642e36 100644 --- a/src/api/product/model.ts +++ b/src/api/product/model.ts @@ -1,4 +1,4 @@ -import type { GetModelAttributeListParams, ModelAttribute, ModelAttributeWithForm, ModelService } from './types' +import type { GetModelAttributeListParams, ModelAttribute, ModelAttributeWithForm, ModelService, SimpleAttribute } from './types' import { defHttp } from '@/utils/http/axios' export function getAllModelServices(productId: string) { @@ -56,3 +56,13 @@ export function deleteModelAttribute(id: string) { url: `/thingModel/item/remove?id=${id}`, }) } + +export function getAllModelAttributes(productId: string, itemType: number) { + return defHttp.get({ + url: '/thingModel/item/queryList', + params: { + productId, + itemType, + }, + }) +} diff --git a/src/api/product/topic.ts b/src/api/product/topic.ts index 893fc562..07c8bcff 100644 --- a/src/api/product/topic.ts +++ b/src/api/product/topic.ts @@ -27,3 +27,12 @@ export function deleteTopic(id: string) { url: `/product/topic/remove?id=${id}`, }) } + +export function getAllTopics(productId: string) { + return defHttp.get({ + url: '/product/topic/list', + params: { + productId, + }, + }) +} diff --git a/src/api/product/types.ts b/src/api/product/types.ts index 19b11752..6ad40e88 100644 --- a/src/api/product/types.ts +++ b/src/api/product/types.ts @@ -57,6 +57,13 @@ export interface GetModelAttributeListParams extends PageParam { modelId?: string } +export enum ModelAttributeDataTypesEnum { + Int32 = 'int32', + Float = 'float', + Bool = 'bool', + Text = 'text', +} + export interface ModelAttribute { id: string name: string @@ -67,6 +74,7 @@ export interface ModelAttribute { tenantId: string method: string sort: number + dataType: ModelAttributeDataTypesEnum dataSpecs?: { min?: number max?: number @@ -82,7 +90,7 @@ export interface ModelAttributeWithForm { name: string itemType: number identifier: string - dataType: number + dataType: ModelAttributeDataTypesEnum min: number max: number maxLength: number @@ -94,3 +102,19 @@ export interface ModelAttributeWithForm { sort: number modelId: string } + +export interface SimpleAttribute { + dataType: ModelAttributeDataTypesEnum + itemType: number + modelId: string + modelName: string + name: string + dataSpecs: { + min: number + max: number + maxLength: number + trueDesc: string + falseDesc: string + scale: string + } +} diff --git a/src/views/device-manage/device/components/CloudCommand.vue b/src/views/device-manage/device/components/CloudCommand.vue index 95397e94..7e2cc12c 100644 --- a/src/views/device-manage/device/components/CloudCommand.vue +++ b/src/views/device-manage/device/components/CloudCommand.vue @@ -1,33 +1,41 @@ diff --git a/src/views/device-manage/device/components/SendCommandModal.vue b/src/views/device-manage/device/components/SendCommandModal.vue new file mode 100644 index 00000000..49076ca9 --- /dev/null +++ b/src/views/device-manage/device/components/SendCommandModal.vue @@ -0,0 +1,175 @@ + + + diff --git a/src/views/device-manage/device/components/composables/useDeviceInfo.ts b/src/views/device-manage/device/components/composables/useDeviceInfo.ts index 7c431724..0f021d51 100644 --- a/src/views/device-manage/device/components/composables/useDeviceInfo.ts +++ b/src/views/device-manage/device/components/composables/useDeviceInfo.ts @@ -1,14 +1,14 @@ +import type { Ref } from 'vue' import { h } from 'vue' import { Tag } from 'ant-design-vue' -import { useRoute } from 'vue-router' -import { useAsyncState } from '@vueuse/core' import MqttParamsModal from '../MqttParamsModal.vue' import MessageModal from '../MessageModal.vue' import type { DescItem } from '@/components/Description' -import { getDeviceDetail, getReportExample } from '@/api/device-manage/device' +import { getReportExample } from '@/api/device-manage/device' import { usePermission } from '@/hooks/web/usePermission' +import type { Device } from '@/api/device-manage/device/types' -export function useDeviceInfo() { +export function useDeviceInfo(data: Ref) { const { hasPermission } = usePermission() const scheam: DescItem[] = [ @@ -78,11 +78,7 @@ export function useDeviceInfo() { }, ] - const route = useRoute() - const { state: data } = useAsyncState(() => getDeviceDetail(route.params.id as string), undefined) - return { - data, scheam, } } diff --git a/src/views/device-manage/device/detail.vue b/src/views/device-manage/device/detail.vue index 194006a9..1b8b402c 100644 --- a/src/views/device-manage/device/detail.vue +++ b/src/views/device-manage/device/detail.vue @@ -1,10 +1,16 @@ @@ -13,13 +19,13 @@ const { hasPermission } = usePermission() - + - + diff --git a/src/views/product/components/ModelAttributeFormModal.vue b/src/views/product/components/ModelAttributeFormModal.vue index b28a601c..768a27b5 100644 --- a/src/views/product/components/ModelAttributeFormModal.vue +++ b/src/views/product/components/ModelAttributeFormModal.vue @@ -5,6 +5,7 @@ import { useMessage } from '@/hooks/web/useMessage' import { BasicForm, useForm } from '@/components/Form' import { BasicModal, useModalInner } from '@/components/Modal' import { createModelAttribute, updateModelAttribute } from '@/api/product/model' +import { ModelAttributeDataTypesEnum } from '@/api/product/types' import type { ModelAttribute, ModelAttributeWithForm } from '@/api/product/types' defineOptions({ name: 'ModelAttributeFormModal' }) @@ -12,13 +13,6 @@ const props = defineProps<{ modelId: string }>() const emit = defineEmits(['success', 'register']) -enum DataTypesEnum { - Int32 = 'int32', - Float = 'float', - Bool = 'bool', - Text = 'text', -} - const isUpdate = ref(false) const [registerForm, { setFieldsValue, validate }] = useForm({ labelWidth: 80, @@ -61,7 +55,7 @@ const [registerForm, { setFieldsValue, validate }] = useForm({ required: true, component: 'Select', componentProps: { - options: Object.values(DataTypesEnum).map(value => ({ label: value, value })), + options: Object.values(ModelAttributeDataTypesEnum).map(value => ({ label: value, value })), }, dynamicDisabled: () => isUpdate.value, }, @@ -77,7 +71,7 @@ const [registerForm, { setFieldsValue, validate }] = useForm({ autoLink: false, }, defaultValue: '_', // skip the required check - ifShow: ({ values }) => [DataTypesEnum.Int32, DataTypesEnum.Float].includes(values.dataType), + ifShow: ({ values }) => [ModelAttributeDataTypesEnum.Int32, ModelAttributeDataTypesEnum.Float].includes(values.dataType), }, { field: 'scale', @@ -88,13 +82,13 @@ const [registerForm, { setFieldsValue, validate }] = useForm({ componentProps: { precision: 0, }, - ifShow: ({ values }) => values.dataType === DataTypesEnum.Float, + ifShow: ({ values }) => values.dataType === ModelAttributeDataTypesEnum.Float, }, { field: 'unit', label: '单位', component: 'Input', - ifShow: ({ values }) => [DataTypesEnum.Int32, DataTypesEnum.Float].includes(values.dataType), + ifShow: ({ values }) => [ModelAttributeDataTypesEnum.Int32, ModelAttributeDataTypesEnum.Float].includes(values.dataType), }, // bool schemas @@ -108,7 +102,7 @@ const [registerForm, { setFieldsValue, validate }] = useForm({ autoLink: false, }, defaultValue: '_', // skip the required check - ifShow: ({ values }) => values.dataType === DataTypesEnum.Bool, + ifShow: ({ values }) => values.dataType === ModelAttributeDataTypesEnum.Bool, }, // text schemas @@ -120,7 +114,7 @@ const [registerForm, { setFieldsValue, validate }] = useForm({ componentProps: { precision: 0, }, - ifShow: ({ values }) => values.dataType === DataTypesEnum.Text, + ifShow: ({ values }) => values.dataType === ModelAttributeDataTypesEnum.Text, }, {