【功能完善】IOT: 物模型数据类型组件完善

pull/620/head
puhui999 2024-12-15 23:15:51 +08:00
parent 488800b304
commit 187b5b03ee
4 changed files with 87 additions and 74 deletions

View File

@ -1,17 +1,40 @@
import request from '@/config/axios' import request from '@/config/axios'
// IoT 产品物模型 VO /**
export interface ThinkModelFunctionVO { * IoT
id: number // 物模型功能编号 */
identifier: string // 功能标识 export interface ThingModelData {
name: string // 功能名称 id?: number // 物模型功能编号
description: string // 功能描述 identifier?: string // 功能标识
productId: number // 产品编号 name?: string // 功能名称
productKey: string // 产品标识 description?: string // 功能描述
type: number // 功能类型 productId?: number // 产品编号
property: string // 属性 productKey?: string // 产品标识
event: string // 事件 type: ProductFunctionTypeEnum // 功能类型
service: string // 服务 property: ThingModelProperty // 属性
event?: ThingModelEvent // 事件
service?: ThingModelService // 服务
}
/**
* ThingModelProperty
*/
export interface ThingModelProperty {
[key: string]: any
}
/**
* ThingModelEvent
*/
export interface ThingModelEvent {
[key: string]: any
}
/**
* ThingModelService
*/
export interface ThingModelService {
[key: string]: any
} }
// IOT 产品功能(物模型)类型枚举类 // IOT 产品功能(物模型)类型枚举类
@ -47,22 +70,17 @@ export const ThinkModelFunctionApi = {
}, },
// 新增产品物模型 // 新增产品物模型
createThinkModelFunction: async (data: ThinkModelFunctionVO) => { createThinkModelFunction: async (data: ThingModelData) => {
return await request.post({ url: `/iot/think-model-function/create`, data }) return await request.post({ url: `/iot/think-model-function/create`, data })
}, },
// 修改产品物模型 // 修改产品物模型
updateThinkModelFunction: async (data: ThinkModelFunctionVO) => { updateThinkModelFunction: async (data: ThingModelData) => {
return await request.put({ url: `/iot/think-model-function/update`, data }) return await request.put({ url: `/iot/think-model-function/update`, data })
}, },
// 删除产品物模型 // 删除产品物模型
deleteThinkModelFunction: async (id: number) => { deleteThinkModelFunction: async (id: number) => {
return await request.delete({ url: `/iot/think-model-function/delete?id=` + id }) return await request.delete({ url: `/iot/think-model-function/delete?id=` + id })
},
// 导出产品物模型 Excel
exportThinkModelFunction: async (params) => {
return await request.download({ url: `/iot/think-model-function/export-excel`, params })
} }
} }

View File

@ -1,6 +1,6 @@
<template> <template>
<el-form-item label="数据类型" prop="dataType"> <el-form-item label="数据类型" prop="dataType">
<el-select v-model="formData.dataType" placeholder="请选择数据类型" @change="handleChange"> <el-select v-model="property.dataType" placeholder="请选择数据类型" @change="handleChange">
<el-option <el-option
v-for="option in dataTypeOptions" v-for="option in dataTypeOptions"
:key="option.value" :key="option.value"
@ -13,19 +13,19 @@
<ThingModelNumberTypeDataSpecs <ThingModelNumberTypeDataSpecs
v-if=" v-if="
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes( [DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
formData.dataType || '' property.dataType || ''
) )
" "
v-model="formData.dataSpecs" v-model="property.dataSpecs"
/> />
<!-- 枚举型配置 --> <!-- 枚举型配置 -->
<ThingModelEnumTypeDataSpecs <ThingModelEnumTypeDataSpecs
v-if="formData.dataType === DataSpecsDataType.ENUM" v-if="property.dataType === DataSpecsDataType.ENUM"
v-model="formData.dataSpecsList" v-model="property.dataSpecsList"
/> />
<!-- 布尔型配置 --> <!-- 布尔型配置 -->
<el-form-item label="布尔值" prop="bool" v-if="formData.dataType === DataSpecsDataType.BOOL"> <el-form-item label="布尔值" prop="bool" v-if="property.dataType === DataSpecsDataType.BOOL">
<template v-for="item in formData.dataSpecsList" :key="item.value"> <template v-for="item in property.dataSpecsList" :key="item.value">
<div class="flex items-center justify-start w-1/1 mb-5px"> <div class="flex items-center justify-start w-1/1 mb-5px">
<span>{{ item.value }}</span> <span>{{ item.value }}</span>
<span class="mx-2">-</span> <span class="mx-2">-</span>
@ -38,20 +38,29 @@
</template> </template>
</el-form-item> </el-form-item>
<!-- 文本型配置 --> <!-- 文本型配置 -->
<el-form-item label="数据长度" prop="text" v-if="formData.dataType === DataSpecsDataType.TEXT"> <el-form-item label="数据长度" prop="text" v-if="property.dataType === DataSpecsDataType.TEXT">
<el-input v-model="formData.length" class="w-255px!" placeholder="请输入文本字节长度"> <el-input v-model="property.length" class="w-255px!" placeholder="请输入文本字节长度">
<template #append>字节</template> <template #append>字节</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<!-- 时间型配置 --> <!-- 时间型配置 -->
<el-form-item label="时间格式" prop="date" v-if="formData.dataType === DataSpecsDataType.DATE"> <el-form-item label="时间格式" prop="date" v-if="property.dataType === DataSpecsDataType.DATE">
<el-input disabled class="w-255px!" placeholder="String类型的UTC时间戳毫秒" /> <el-input disabled class="w-255px!" placeholder="String类型的UTC时间戳毫秒" />
</el-form-item> </el-form-item>
<!-- 数组型配置--> <!-- 数组型配置-->
<ThingModelArrayTypeDataSpecs <ThingModelArrayTypeDataSpecs
v-model="formData.dataSpecs" v-model="property.dataSpecs"
v-if="formData.dataType === DataSpecsDataType.ARRAY" v-if="property.dataType === DataSpecsDataType.ARRAY"
/> />
<el-form-item label="读写类型" prop="accessMode">
<el-radio-group v-model="property.accessMode">
<el-radio label="rw">读写</el-radio>
<el-radio label="r">只读</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="属性描述" prop="description">
<el-input v-model="property.description" placeholder="请输入属性描述" type="textarea" />
</el-form-item>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -62,30 +71,31 @@ import {
ThingModelEnumTypeDataSpecs, ThingModelEnumTypeDataSpecs,
ThingModelNumberTypeDataSpecs ThingModelNumberTypeDataSpecs
} from './dataSpecs' } from './dataSpecs'
import { ThingModelProperty } from '@/api/iot/thinkmodelfunction'
/** 物模型数据 */ /** 物模型数据 */
defineOptions({ name: 'ThingModelDataSpecs' }) defineOptions({ name: 'ThingModelDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const formData = useVModel(props, 'modelValue', emits) as Ref<any> const property = useVModel(props, 'modelValue', emits) as Ref<ThingModelProperty>
/** 属性值的数据类型切换时初始化相关数据 */ /** 属性值的数据类型切换时初始化相关数据 */
const handleChange = (dataType: any) => { const handleChange = (dataType: any) => {
formData.value.dataSpecsList = [] property.value.dataSpecsList = []
formData.value.dataSpecs = {} property.value.dataSpecs = {}
switch (dataType) { switch (dataType) {
case DataSpecsDataType.INT: case DataSpecsDataType.INT:
formData.value.dataSpecs.dataType = DataSpecsDataType.INT property.value.dataSpecs.dataType = DataSpecsDataType.INT
break break
case DataSpecsDataType.DOUBLE: case DataSpecsDataType.DOUBLE:
formData.value.dataSpecs.dataType = DataSpecsDataType.DOUBLE property.value.dataSpecs.dataType = DataSpecsDataType.DOUBLE
break break
case DataSpecsDataType.FLOAT: case DataSpecsDataType.FLOAT:
formData.value.dataSpecs.dataType = DataSpecsDataType.FLOAT property.value.dataSpecs.dataType = DataSpecsDataType.FLOAT
break break
case DataSpecsDataType.ENUM: case DataSpecsDataType.ENUM:
formData.value.dataSpecsList.push({ property.value.dataSpecsList.push({
dataType: DataSpecsDataType.ENUM, dataType: DataSpecsDataType.ENUM,
name: '', // name: '', //
value: undefined // value: undefined //
@ -93,7 +103,7 @@ const handleChange = (dataType: any) => {
break break
case DataSpecsDataType.BOOL: case DataSpecsDataType.BOOL:
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
formData.value.dataSpecsList.push({ property.value.dataSpecsList.push({
dataType: DataSpecsDataType.BOOL, dataType: DataSpecsDataType.BOOL,
name: '', // name: '', //
value: i // value: i //
@ -101,7 +111,7 @@ const handleChange = (dataType: any) => {
} }
break break
case DataSpecsDataType.ARRAY: case DataSpecsDataType.ARRAY:
formData.value.dataSpecs.dataType = DataSpecsDataType.ARRAY property.value.dataSpecs.dataType = DataSpecsDataType.ARRAY
break break
} }
} }

View File

@ -20,16 +20,11 @@
<el-form-item label="标识符" prop="identifier"> <el-form-item label="标识符" prop="identifier">
<el-input v-model="formData.identifier" placeholder="请输入标识符" /> <el-input v-model="formData.identifier" placeholder="请输入标识符" />
</el-form-item> </el-form-item>
<ThingModelDataSpecs v-model="formData" /> <!-- 属性配置 -->
<el-form-item label="读写类型" prop="accessMode"> <ThingModelDataSpecs
<el-radio-group v-model="formData.accessMode"> v-model="formData.property"
<el-radio label="rw">读写</el-radio> v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
<el-radio label="r">只读</el-radio> />
</el-radio-group>
</el-form-item>
<el-form-item label="属性描述" prop="property.description">
<el-input v-model="formData.description" placeholder="请输入属性描述" type="textarea" />
</el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
@ -45,7 +40,7 @@ import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
import { import {
ProductFunctionTypeEnum, ProductFunctionTypeEnum,
ThinkModelFunctionApi, ThinkModelFunctionApi,
ThinkModelFunctionVO ThingModelData
} from '@/api/iot/thinkmodelfunction' } from '@/api/iot/thinkmodelfunction'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
import { DataSpecsDataType } from './config' import { DataSpecsDataType } from './config'
@ -61,18 +56,13 @@ const dialogVisible = ref(false)
const dialogTitle = ref('') const dialogTitle = ref('')
const formLoading = ref(false) const formLoading = ref(false)
const formType = ref('') const formType = ref('')
const formData = ref({ const formData = ref<ThingModelData>({
id: undefined,
productId: undefined,
productKey: undefined,
identifier: undefined,
name: undefined,
description: undefined,
type: ProductFunctionTypeEnum.PROPERTY, type: ProductFunctionTypeEnum.PROPERTY,
property: {
dataType: DataSpecsDataType.INT, dataType: DataSpecsDataType.INT,
dataSpecsList: [], dataSpecsList: [],
dataSpecs: {}, dataSpecs: {}
accessMode: undefined }
}) })
const formRules = reactive({ const formRules = reactive({
name: [ name: [
@ -138,7 +128,7 @@ const submitForm = async () => {
await formRef.value.validate() await formRef.value.validate()
formLoading.value = true formLoading.value = true
try { try {
const data = formData.value as unknown as ThinkModelFunctionVO const data = formData.value as unknown as ThingModelData
data.productId = product!.value.id data.productId = product!.value.id
data.productKey = product!.value.productKey data.productKey = product!.value.productKey
if (formType.value === 'create') { if (formType.value === 'create') {
@ -158,17 +148,12 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
id: undefined,
productId: undefined,
productKey: undefined,
identifier: undefined,
name: undefined,
description: undefined,
type: ProductFunctionTypeEnum.PROPERTY, type: ProductFunctionTypeEnum.PROPERTY,
property: {
dataType: DataSpecsDataType.INT, dataType: DataSpecsDataType.INT,
dataSpecsList: [], dataSpecsList: [],
dataSpecs: {}, dataSpecs: {}
accessMode: undefined }
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

View File

@ -24,7 +24,7 @@
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { DataSpecsDataType, dataTypeOptions } from '../config' import { DataSpecsDataType, dataTypeOptions } from '../config'
/** 数型的 dataSpecs 配置组件 */ /** 数型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' }) defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])