【代码优化】IOT: 产品物模型独立包
parent
c8ab57f726
commit
341eb570e9
|
@ -3,7 +3,7 @@ import request from '@/config/axios'
|
|||
/**
|
||||
* IoT 产品物模型
|
||||
*/
|
||||
export interface ThingModelData {
|
||||
export interface ThinkModelData {
|
||||
id?: number // 物模型功能编号
|
||||
identifier?: string // 功能标识
|
||||
name?: string // 功能名称
|
||||
|
@ -12,29 +12,29 @@ export interface ThingModelData {
|
|||
productKey?: string // 产品标识
|
||||
dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致
|
||||
type: ProductFunctionTypeEnum // 功能类型
|
||||
property: ThingModelProperty // 属性
|
||||
event?: ThingModelEvent // 事件
|
||||
service?: ThingModelService // 服务
|
||||
property: ThinkModelProperty // 属性
|
||||
event?: ThinkModelEvent // 事件
|
||||
service?: ThinkModelService // 服务
|
||||
}
|
||||
|
||||
/**
|
||||
* ThingModelProperty 类型
|
||||
* ThinkModelProperty 类型
|
||||
*/
|
||||
export interface ThingModelProperty {
|
||||
export interface ThinkModelProperty {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* ThingModelEvent 类型
|
||||
* ThinkModelEvent 类型
|
||||
*/
|
||||
export interface ThingModelEvent {
|
||||
export interface ThinkModelEvent {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/**
|
||||
* ThingModelService 类型
|
||||
* ThinkModelService 类型
|
||||
*/
|
||||
export interface ThingModelService {
|
||||
export interface ThinkModelService {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
|
@ -52,14 +52,14 @@ export enum ProductFunctionAccessModeEnum {
|
|||
}
|
||||
|
||||
// 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 })
|
||||
},
|
||||
|
||||
// 获得产品物模型
|
||||
getProductThingModelListByProductId: async (params: any) => {
|
||||
getProductThinkModelListByProductId: async (params: any) => {
|
||||
return await request.get({
|
||||
url: `/iot/product-thing-model/list-by-product-id`,
|
||||
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 })
|
||||
},
|
||||
|
||||
// 新增产品物模型
|
||||
createProductThingModel: async (data: ThingModelData) => {
|
||||
createProductThinkModel: async (data: ThinkModelData) => {
|
||||
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 })
|
||||
},
|
||||
|
||||
// 删除产品物模型
|
||||
deleteProductThingModel: async (id: number) => {
|
||||
deleteProductThinkModel: async (id: number) => {
|
||||
return await request.delete({ url: `/iot/product-thing-model/delete?id=` + id })
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import ThingModelEnumTypeDataSpecs from './ThingModelEnumTypeDataSpecs.vue'
|
||||
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
|
||||
import ThingModelArrayTypeDataSpecs from './ThingModelArrayTypeDataSpecs.vue'
|
||||
|
||||
export { ThingModelEnumTypeDataSpecs, ThingModelNumberTypeDataSpecs, ThingModelArrayTypeDataSpecs }
|
|
@ -8,8 +8,8 @@
|
|||
<el-tab-pane label="Topic 类列表" name="topic">
|
||||
<ProductTopic v-if="activeTab === 'topic'" :product="product" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="功能定义" lazy name="thingModel">
|
||||
<IoTProductThingModel ref="thingModelRef" />
|
||||
<el-tab-pane label="功能定义" lazy name="thinkModel">
|
||||
<IoTProductThinkModel ref="thinkModelRef" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="消息解析" name="message" />
|
||||
<el-tab-pane label="服务端订阅" name="subscription" />
|
||||
|
@ -22,7 +22,7 @@ import { DeviceApi } from '@/api/iot/device'
|
|||
import ProductDetailsHeader from './ProductDetailsHeader.vue'
|
||||
import ProductDetailsInfo from './ProductDetailsInfo.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 { useRouter } from 'vue-router'
|
||||
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
|
||||
|
|
|
@ -309,7 +309,7 @@ const openObjectModel = (item: ProductVO) => {
|
|||
push({
|
||||
name: 'IoTProductDetail',
|
||||
params: { id: item.id },
|
||||
query: { tab: 'thingModel' }
|
||||
query: { tab: 'thinkModel' }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- 数值型配置 -->
|
||||
<ThingModelNumberTypeDataSpecs
|
||||
<ThinkModelNumberTypeDataSpecs
|
||||
v-if="
|
||||
[DataSpecsDataType.INT, DataSpecsDataType.DOUBLE, DataSpecsDataType.FLOAT].includes(
|
||||
property.dataType || ''
|
||||
|
@ -23,7 +23,7 @@
|
|||
v-model="property.dataSpecs"
|
||||
/>
|
||||
<!-- 枚举型配置 -->
|
||||
<ThingModelEnumTypeDataSpecs
|
||||
<ThinkModelEnumTypeDataSpecs
|
||||
v-if="property.dataType === DataSpecsDataType.ENUM"
|
||||
v-model="property.dataSpecsList"
|
||||
/>
|
||||
|
@ -74,7 +74,7 @@
|
|||
<el-input class="w-255px!" disabled placeholder="String类型的UTC时间戳(毫秒)" />
|
||||
</el-form-item>
|
||||
<!-- 数组型配置-->
|
||||
<ThingModelArrayTypeDataSpecs
|
||||
<ThinkModelArrayTypeDataSpecs
|
||||
v-if="property.dataType === DataSpecsDataType.ARRAY"
|
||||
v-model="property.dataSpecs"
|
||||
/>
|
||||
|
@ -104,18 +104,18 @@
|
|||
import { useVModel } from '@vueuse/core'
|
||||
import { DataSpecsDataType, dataTypeOptions } from './config'
|
||||
import {
|
||||
ThingModelArrayTypeDataSpecs,
|
||||
ThingModelEnumTypeDataSpecs,
|
||||
ThingModelNumberTypeDataSpecs
|
||||
ThinkModelArrayTypeDataSpecs,
|
||||
ThinkModelEnumTypeDataSpecs,
|
||||
ThinkModelNumberTypeDataSpecs
|
||||
} from './dataSpecs'
|
||||
import { ThingModelProperty } from '@/api/iot/thinkmodelfunction'
|
||||
import { ThinkModelProperty } from '@/api/iot/thinkmodel'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 物模型数据 */
|
||||
defineOptions({ name: 'ThingModelDataSpecs' })
|
||||
defineOptions({ name: 'IoTProductThinkModelDataSpecs' })
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
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) => {
|
|
@ -21,7 +21,7 @@
|
|||
<el-input v-model="formData.identifier" placeholder="请输入标识符" />
|
||||
</el-form-item>
|
||||
<!-- 属性配置 -->
|
||||
<ThingModelDataSpecs
|
||||
<ThinkModelDataSpecs
|
||||
v-if="formData.type === ProductFunctionTypeEnum.PROPERTY"
|
||||
v-model="formData.property"
|
||||
/>
|
||||
|
@ -36,17 +36,13 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { ProductVO } from '@/api/iot/product/product'
|
||||
import ThingModelDataSpecs from './ThingModelDataSpecs.vue'
|
||||
import {
|
||||
ProductFunctionTypeEnum,
|
||||
ThingModelData,
|
||||
ThinkModelFunctionApi
|
||||
} from '@/api/iot/thinkmodelfunction'
|
||||
import ThinkModelDataSpecs from './ThinkModelDataSpecs.vue'
|
||||
import { ProductFunctionTypeEnum, ThinkModelApi, ThinkModelData } from '@/api/iot/thinkmodel'
|
||||
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
|
||||
import { DataSpecsDataType } from './config'
|
||||
import { cloneDeep } from 'lodash-es'
|
||||
|
||||
defineOptions({ name: 'IoTProductThingModelForm' })
|
||||
defineOptions({ name: 'IoTProductThinkModelForm' })
|
||||
|
||||
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) // 注入产品信息
|
||||
|
||||
|
@ -57,7 +53,7 @@ const dialogVisible = ref(false)
|
|||
const dialogTitle = ref('')
|
||||
const formLoading = ref(false)
|
||||
const formType = ref('')
|
||||
const formData = ref<ThingModelData>({
|
||||
const formData = ref<ThinkModelData>({
|
||||
type: ProductFunctionTypeEnum.PROPERTY,
|
||||
dataType: DataSpecsDataType.INT,
|
||||
property: {
|
||||
|
@ -115,7 +111,7 @@ const open = async (type: string, id?: number) => {
|
|||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await ThinkModelFunctionApi.getProductThingModel(id)
|
||||
formData.value = await ThinkModelApi.getProductThinkModel(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
|
@ -129,7 +125,7 @@ const submitForm = async () => {
|
|||
await formRef.value.validate()
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = cloneDeep(formData.value) as ThingModelData
|
||||
const data = cloneDeep(formData.value) as ThinkModelData
|
||||
// 信息补全
|
||||
data.productId = product!.value.id
|
||||
data.productKey = product!.value.productKey
|
||||
|
@ -138,10 +134,10 @@ const submitForm = async () => {
|
|||
data.property.identifier = data.identifier
|
||||
data.property.name = data.name
|
||||
if (formType.value === 'create') {
|
||||
await ThinkModelFunctionApi.createProductThingModel(data)
|
||||
await ThinkModelApi.createProductThinkModel(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ThinkModelFunctionApi.updateProductThingModel(data)
|
||||
await ThinkModelApi.updateProductThinkModel(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
} finally {
|
|
@ -37,7 +37,7 @@ import { DataSpecsDataType, dataTypeOptions } from '../config'
|
|||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 数组型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThingModelArrayTypeDataSpecs' })
|
||||
defineOptions({ name: 'IoTProductThinkModelArrayTypeDataSpecs' })
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>
|
|
@ -44,14 +44,11 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { useVModel } from '@vueuse/core'
|
||||
import {
|
||||
DataSpecsDataType,
|
||||
DataSpecsEnumOrBoolDataVO
|
||||
} from '@/views/iot/product/product/detail/ThingModel/config'
|
||||
import { DataSpecsDataType, DataSpecsEnumOrBoolDataVO } from '../config'
|
||||
import { isEmpty } from '@/utils/is'
|
||||
|
||||
/** 枚举型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThingModelEnumTypeDataSpecs' })
|
||||
defineOptions({ name: 'IoTProductThinkModelEnumTypeDataSpecs' })
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<DataSpecsEnumOrBoolDataVO[]>
|
|
@ -62,7 +62,7 @@ import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
|
|||
import { DataSpecsNumberDataVO } from '../config'
|
||||
|
||||
/** 数值型的 dataSpecs 配置组件 */
|
||||
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
|
||||
defineOptions({ name: 'IoTProductThinkModelNumberTypeDataSpecs' })
|
||||
const props = defineProps<{ modelValue: any }>()
|
||||
const emits = defineEmits(['update:modelValue'])
|
||||
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<DataSpecsNumberDataVO>
|
|
@ -0,0 +1,5 @@
|
|||
import ThinkModelEnumTypeDataSpecs from './ThinkModelEnumTypeDataSpecs.vue'
|
||||
import ThinkModelNumberTypeDataSpecs from './ThinkModelNumberTypeDataSpecs.vue'
|
||||
import ThinkModelArrayTypeDataSpecs from './ThinkModelArrayTypeDataSpecs.vue'
|
||||
|
||||
export { ThinkModelEnumTypeDataSpecs, ThinkModelNumberTypeDataSpecs, ThinkModelArrayTypeDataSpecs }
|
|
@ -96,23 +96,23 @@
|
|||
</el-tabs>
|
||||
</ContentWrap>
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<ThingModelForm ref="formRef" @success="getList" />
|
||||
<ThinkModelForm ref="formRef" @success="getList" />
|
||||
</template>
|
||||
<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 ThingModelForm from './ThingModelForm.vue'
|
||||
import ThinkModelForm from './ThinkModelForm.vue'
|
||||
import { ProductVO } from '@/api/iot/product/product'
|
||||
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 message = useMessage() // 消息弹窗
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<ThingModelData[]>([]) // 列表的数据
|
||||
const list = ref<ThinkModelData[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
|
@ -130,7 +130,7 @@ const getList = async () => {
|
|||
loading.value = true
|
||||
try {
|
||||
queryParams.productId = product?.value?.id || -1
|
||||
const data = await ThinkModelFunctionApi.getProductThingModelPage(queryParams)
|
||||
const data = await ThinkModelApi.getProductThinkModelPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
|
@ -162,7 +162,7 @@ const handleDelete = async (id: number) => {
|
|||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await ThinkModelFunctionApi.deleteProductThingModel(id)
|
||||
await ThinkModelApi.deleteProductThinkModel(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
Loading…
Reference in New Issue