【代码优化】IOT: 产品物模型独立包

pull/622/head
puhui999 2024-12-17 15:39:19 +08:00
parent c8ab57f726
commit 341eb570e9
12 changed files with 56 additions and 63 deletions

View File

@ -3,7 +3,7 @@ import request from '@/config/axios'
/** /**
* IoT * IoT
*/ */
export interface ThingModelData { export interface ThinkModelData {
id?: number // 物模型功能编号 id?: number // 物模型功能编号
identifier?: string // 功能标识 identifier?: string // 功能标识
name?: string // 功能名称 name?: string // 功能名称
@ -12,29 +12,29 @@ export interface ThingModelData {
productKey?: string // 产品标识 productKey?: string // 产品标识
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致 dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
type: ProductFunctionTypeEnum // 功能类型 type: ProductFunctionTypeEnum // 功能类型
property: ThingModelProperty // 属性 property: ThinkModelProperty // 属性
event?: ThingModelEvent // 事件 event?: ThinkModelEvent // 事件
service?: ThingModelService // 服务 service?: ThinkModelService // 服务
} }
/** /**
* ThingModelProperty * ThinkModelProperty
*/ */
export interface ThingModelProperty { export interface ThinkModelProperty {
[key: string]: any [key: string]: any
} }
/** /**
* ThingModelEvent * ThinkModelEvent
*/ */
export interface ThingModelEvent { export interface ThinkModelEvent {
[key: string]: any [key: string]: any
} }
/** /**
* ThingModelService * ThinkModelService
*/ */
export interface ThingModelService { export interface ThinkModelService {
[key: string]: any [key: string]: any
} }
@ -52,14 +52,14 @@ export enum ProductFunctionAccessModeEnum {
} }
// IoT 产品物模型 API // IoT 产品物模型 API
export const ThinkModelFunctionApi = { export const ThinkModelApi = {
// 查询产品物模型分页 // 查询产品物模型分页
getProductThingModelPage: async (params: any) => { getProductThinkModelPage: async (params: any) => {
return await request.get({ url: `/iot/product-thing-model/page`, params }) return await request.get({ url: `/iot/product-thing-model/page`, params })
}, },
// 获得产品物模型 // 获得产品物模型
getProductThingModelListByProductId: async (params: any) => { getProductThinkModelListByProductId: async (params: any) => {
return await request.get({ return await request.get({
url: `/iot/product-thing-model/list-by-product-id`, url: `/iot/product-thing-model/list-by-product-id`,
params params
@ -67,22 +67,22 @@ export const ThinkModelFunctionApi = {
}, },
// 查询产品物模型详情 // 查询产品物模型详情
getProductThingModel: async (id: number) => { getProductThinkModel: async (id: number) => {
return await request.get({ url: `/iot/product-thing-model/get?id=` + id }) return await request.get({ url: `/iot/product-thing-model/get?id=` + id })
}, },
// 新增产品物模型 // 新增产品物模型
createProductThingModel: async (data: ThingModelData) => { createProductThinkModel: async (data: ThinkModelData) => {
return await request.post({ url: `/iot/product-thing-model/create`, data }) return await request.post({ url: `/iot/product-thing-model/create`, data })
}, },
// 修改产品物模型 // 修改产品物模型
updateProductThingModel: async (data: ThingModelData) => { updateProductThinkModel: async (data: ThinkModelData) => {
return await request.put({ url: `/iot/product-thing-model/update`, data }) return await request.put({ url: `/iot/product-thing-model/update`, data })
}, },
// 删除产品物模型 // 删除产品物模型
deleteProductThingModel: async (id: number) => { deleteProductThinkModel: async (id: number) => {
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id }) return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
} }
} }

View File

@ -1,5 +0,0 @@
import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }

View File

@ -8,8 +8,8 @@
<el-tab-pane label="Topic 类列表" name="topic"> <el-tab-pane label="Topic 类列表" name="topic">
<ProductTopic v-if="activeTab === 'topic'" :product="product" /> <ProductTopic v-if="activeTab === 'topic'" :product="product" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="功能定义" lazy name="thingModel"> <el-tab-pane label="功能定义" lazy name="thinkModel">
<IoTProductThingModel ref="thingModelRef" /> <IoTProductThinkModel ref="thinkModelRef" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="消息解析" name="message" /> <el-tab-pane label="消息解析" name="message" />
<el-tab-pane label="服务端订阅" name="subscription" /> <el-tab-pane label="服务端订阅" name="subscription" />
@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device'
import ProductDetailsHeader from './ProductDetailsHeader.vue' import ProductDetailsHeader from './ProductDetailsHeader.vue'
import ProductDetailsInfo from './ProductDetailsInfo.vue' import ProductDetailsInfo from './ProductDetailsInfo.vue'
import ProductTopic from './ProductTopic.vue' import ProductTopic from './ProductTopic.vue'
import IoTProductThingModel from './ThingModel/index.vue' import IoTProductThinkModel from '@/views/iot/thinkmodel/index.vue'
import { useTagsViewStore } from '@/store/modules/tagsView' import { useTagsViewStore } from '@/store/modules/tagsView'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'

View File

@ -309,7 +309,7 @@ const openObjectModel = (item: ProductVO) => {
push({ push({
name: 'IoTProductDetail', name: 'IoTProductDetail',
params: { id: item.id }, params: { id: item.id },
query: { tab: 'thingModel' } query: { tab: 'thinkModel' }
}) })
} }

View File

@ -14,7 +14,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 数值型配置 --> <!-- 数值型配置 -->
<ThingModelNumberTypeDataSpecs <ThinkModelNumberTypeDataSpecs
v-if=" v-if="
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes( [DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
property.dataType || '' property.dataType || ''
@ -23,7 +23,7 @@
v-model="property.dataSpecs" v-model="property.dataSpecs"
/> />
<!-- 枚举型配置 --> <!-- 枚举型配置 -->
<ThingModelEnumTypeDataSpecs <ThinkModelEnumTypeDataSpecs
v-if="property.dataType === DataSpecsDataType.ENUM" v-if="property.dataType === DataSpecsDataType.ENUM"
v-model="property.dataSpecsList" v-model="property.dataSpecsList"
/> />
@ -74,7 +74,7 @@
<el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳毫秒" /> <el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳毫秒" />
</el-form-item> </el-form-item>
<!-- 数组型配置--> <!-- 数组型配置-->
<ThingModelArrayTypeDataSpecs <ThinkModelArrayTypeDataSpecs
v-if="property.dataType === DataSpecsDataType.ARRAY" v-if="property.dataType === DataSpecsDataType.ARRAY"
v-model="property.dataSpecs" v-model="property.dataSpecs"
/> />
@ -104,18 +104,18 @@
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { DataSpecsDataType, dataTypeOptions } from './config' import { DataSpecsDataType, dataTypeOptions } from './config'
import { import {
ThingModelArrayTypeDataSpecs, ThinkModelArrayTypeDataSpecs,
ThingModelEnumTypeDataSpecs, ThinkModelEnumTypeDataSpecs,
ThingModelNumberTypeDataSpecs ThinkModelNumberTypeDataSpecs
} from './dataSpecs' } from './dataSpecs'
import { ThingModelProperty } from '@/api/iot/thinkmodelfunction' import { ThinkModelProperty } from '@/api/iot/thinkmodel'
import { isEmpty } from '@/utils/is' import { isEmpty } from '@/utils/is'
/** 物模型数据 */ /** 物模型数据 */
defineOptions({ name: 'ThingModelDataSpecs' }) defineOptions({ name: 'IoTProductThinkModelDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const property = useVModel(props, 'modelValue', emits) as Ref<ThingModelProperty> const property = useVModel(props, 'modelValue', emits) as Ref<ThinkModelProperty>
/** 属性值的数据类型切换时初始化相关数据 */ /** 属性值的数据类型切换时初始化相关数据 */
const handleChange = (dataType: any) => { const handleChange = (dataType: any) => {

View File

@ -21,7 +21,7 @@
<el-input v-model="formData.identifier" placeholder="请输入标识符" /> <el-input v-model="formData.identifier" placeholder="请输入标识符" />
</el-form-item> </el-form-item>
<!-- 属性配置 --> <!-- 属性配置 -->
<ThingModelDataSpecs <ThinkModelDataSpecs
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY" v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
v-model="formData.property" v-model="formData.property"
/> />
@ -36,17 +36,13 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ProductVO } from '@/api/iot/product/product' import { ProductVO } from '@/api/iot/product/product'
import ThingModelDataSpecs from './ThingModelDataSpecs.vue' import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue'
import { import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
ProductFunctionTypeEnum,
ThingModelData,
ThinkModelFunctionApi
} 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'
import { cloneDeep } from 'lodash-es' import { cloneDeep } from 'lodash-es'
defineOptions({ name: 'IoTProductThingModelForm' }) defineOptions({ name: 'IoTProductThinkModelForm' })
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) //
@ -57,7 +53,7 @@ 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<ThingModelData>({ const formData = ref<ThinkModelData>({
type: ProductFunctionTypeEnum.PROPERTY, type: ProductFunctionTypeEnum.PROPERTY,
dataType: DataSpecsDataType.INT, dataType: DataSpecsDataType.INT,
property: { property: {
@ -115,7 +111,7 @@ const open = async (type: string, id?: number) => {
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await ThinkModelFunctionApi.getProductThingModel(id) formData.value = await ThinkModelApi.getProductThinkModel(id)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
@ -129,7 +125,7 @@ const submitForm = async () => {
await formRef.value.validate() await formRef.value.validate()
formLoading.value = true formLoading.value = true
try { try {
const data = cloneDeep(formData.value) as ThingModelData const data = cloneDeep(formData.value) as ThinkModelData
// //
data.productId = product!.value.id data.productId = product!.value.id
data.productKey = product!.value.productKey data.productKey = product!.value.productKey
@ -138,10 +134,10 @@ const submitForm = async () => {
data.property.identifier = data.identifier data.property.identifier = data.identifier
data.property.name = data.name data.property.name = data.name
if (formType.value === 'create') { if (formType.value === 'create') {
await ThinkModelFunctionApi.createProductThingModel(data) await ThinkModelApi.createProductThinkModel(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await ThinkModelFunctionApi.updateProductThingModel(data) await ThinkModelApi.updateProductThinkModel(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
} finally { } finally {

View File

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

View File

@ -44,14 +44,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
DataSpecsDataType,
DataSpecsEnumOrBoolDataVO
} from '@/views/iot/product/product/detail/ThingModel/config'
import { isEmpty } from '@/utils/is' import { isEmpty } from '@/utils/is'
/** 枚举型的 dataSpecs 配置组件 */ /** 枚举型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelEnumTypeDataSpecs' }) defineOptions({ name: 'IoTProductThinkModelEnumTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]> const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]>

View File

@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
import { DataSpecsNumberDataVO } from '../config' import { DataSpecsNumberDataVO } from '../config'
/** 数值型的 dataSpecs 配置组件 */ /** 数值型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' }) defineOptions({ name: 'IoTProductThinkModelNumberTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>() const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO> const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO>

View File

@ -0,0 +1,5 @@
import ThinkModelEnumTypeDataSpecs from './ThinkModelEnumTypeDataSpecs.vue'
import ThinkModelNumberTypeDataSpecs from './ThinkModelNumberTypeDataSpecs.vue'
import ThinkModelArrayTypeDataSpecs from './ThinkModelArrayTypeDataSpecs.vue'
export { ThinkModelEnumTypeDataSpecs, ThinkModelNumberTypeDataSpecs, ThinkModelArrayTypeDataSpecs }

View File

@ -96,23 +96,23 @@
</el-tabs> </el-tabs>
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<ThingModelForm ref="formRef" @success="getList" /> <ThinkModelForm ref="formRef" @success="getList" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ThingModelData, ThinkModelFunctionApi } from '@/api/iot/thinkmodelfunction' import { ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import ThingModelForm from './ThingModelForm.vue' import ThinkModelForm from './ThinkModelForm.vue'
import { ProductVO } from '@/api/iot/product/product' import { ProductVO } from '@/api/iot/product/product'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
import { getDataTypeOptionsLabel } from '@/views/iot/product/product/detail/ThingModel/config' import { getDataTypeOptionsLabel } from '@/views/iot/thinkmodel/config'
defineOptions({ name: 'IoTProductThingModel' }) defineOptions({ name: 'IoTProductThinkModel' })
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
const list = ref<ThingModelData[]>([]) // const list = ref<ThinkModelData[]>([]) //
const total = ref(0) // const total = ref(0) //
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
@ -130,7 +130,7 @@ const getList = async () => {
loading.value = true loading.value = true
try { try {
queryParams.productId = product?.value?.id || -1 queryParams.productId = product?.value?.id || -1
const data = await ThinkModelFunctionApi.getProductThingModelPage(queryParams) const data = await ThinkModelApi.getProductThinkModelPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -162,7 +162,7 @@ const handleDelete = async (id: number) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await ThinkModelFunctionApi.deleteProductThingModel(id) await ThinkModelApi.deleteProductThinkModel(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()