feat:【IoT 物联网】简化部分 thingmodel 维护的代码
parent
677b0d61ca
commit
4af1875001
|
|
@ -6,15 +6,12 @@
|
||||||
prop="event.type"
|
prop="event.type"
|
||||||
>
|
>
|
||||||
<el-radio-group v-model="thingModelEvent.type">
|
<el-radio-group v-model="thingModelEvent.type">
|
||||||
<!-- TODO @AI:使用枚举 -->
|
<el-radio
|
||||||
<el-radio :value="IoTThingModelEventTypeEnum.INFO.value">
|
v-for="eventType in Object.values(IoTThingModelEventTypeEnum)"
|
||||||
{{ IoTThingModelEventTypeEnum.INFO.label }}
|
:key="eventType.value"
|
||||||
</el-radio>
|
:value="eventType.value"
|
||||||
<el-radio :value="IoTThingModelEventTypeEnum.ALERT.value">
|
>
|
||||||
{{ IoTThingModelEventTypeEnum.ALERT.label }}
|
{{ eventType.label }}
|
||||||
</el-radio>
|
|
||||||
<el-radio :value="IoTThingModelEventTypeEnum.ERROR.value">
|
|
||||||
{{ IoTThingModelEventTypeEnum.ERROR.label }}
|
|
||||||
</el-radio>
|
</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,8 @@ const submitForm = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 填写额外的属性 */
|
/** 填写额外的属性(处理不同类型的情况) */
|
||||||
const fillExtraAttributes = (data: any) => {
|
const fillExtraAttributes = (data: any) => {
|
||||||
// 处理不同类型的情况
|
|
||||||
// 属性
|
// 属性
|
||||||
if (data.type === IoTThingModelTypeEnum.PROPERTY) {
|
if (data.type === IoTThingModelTypeEnum.PROPERTY) {
|
||||||
removeDataSpecs(data.property)
|
removeDataSpecs(data.property)
|
||||||
|
|
@ -191,6 +190,7 @@ const fillExtraAttributes = (data: any) => {
|
||||||
delete data.service
|
delete data.service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 处理 dataSpecs 为空的情况 */
|
/** 处理 dataSpecs 为空的情况 */
|
||||||
const removeDataSpecs = (val: any) => {
|
const removeDataSpecs = (val: any) => {
|
||||||
if (isEmpty(val.dataSpecs)) {
|
if (isEmpty(val.dataSpecs)) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<el-button link type="primary" @click="openParamForm(null)">+新增参数</el-button>
|
<el-button link type="primary" @click="openParamForm(null)">+新增参数</el-button>
|
||||||
|
|
||||||
<!-- param 表单 -->
|
<!-- param 表单 -->
|
||||||
<Dialog v-model="dialogVisible" :title="dialogTitle" append-to-body>
|
<Dialog v-model="dialogVisible" title="新增参数" append-to-body>
|
||||||
<el-form
|
<el-form
|
||||||
ref="paramFormRef"
|
ref="paramFormRef"
|
||||||
v-loading="formLoading"
|
v-loading="formLoading"
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
<!-- 属性配置 -->
|
<!-- 属性配置 -->
|
||||||
<ThingModelProperty v-model="formData.property" is-params />
|
<ThingModelProperty v-model="formData.property" is-params />
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
|
@ -54,7 +53,6 @@ const props = defineProps<{ modelValue: any; direction: string }>()
|
||||||
const emits = defineEmits(['update:modelValue'])
|
const emits = defineEmits(['update:modelValue'])
|
||||||
const thingModelParams = useVModel(props, 'modelValue', emits) as Ref<any[]>
|
const thingModelParams = useVModel(props, 'modelValue', emits) as Ref<any[]>
|
||||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
const dialogTitle = ref('新增参数') // 弹窗的标题
|
|
||||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
const paramFormRef = ref() // 表单 ref
|
const paramFormRef = ref() // 表单 ref
|
||||||
const formData = ref<any>({
|
const formData = ref<any>({
|
||||||
|
|
@ -101,8 +99,8 @@ const submitForm = async () => {
|
||||||
// 校验参数
|
// 校验参数
|
||||||
await paramFormRef.value.validate()
|
await paramFormRef.value.validate()
|
||||||
try {
|
try {
|
||||||
const data = unref(formData)
|
|
||||||
// 构建数据对象
|
// 构建数据对象
|
||||||
|
const data = unref(formData)
|
||||||
const item = {
|
const item = {
|
||||||
identifier: data.identifier,
|
identifier: data.identifier,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
|
@ -117,19 +115,16 @@ const submitForm = async () => {
|
||||||
dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
|
dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找是否已有相同 identifier 的项
|
// 新增或修改同 identifier 的参数
|
||||||
const existingIndex = thingModelParams.value.findIndex(
|
const existingIndex = thingModelParams.value.findIndex(
|
||||||
(spec) => spec.identifier === data.identifier
|
(spec) => spec.identifier === data.identifier
|
||||||
)
|
)
|
||||||
if (existingIndex > -1) {
|
if (existingIndex > -1) {
|
||||||
// 更新已有项
|
|
||||||
thingModelParams.value[existingIndex] = item
|
thingModelParams.value[existingIndex] = item
|
||||||
} else {
|
} else {
|
||||||
// 添加新项
|
|
||||||
thingModelParams.value.push(item)
|
thingModelParams.value.push(item)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// 隐藏对话框
|
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,13 +83,13 @@
|
||||||
v-model="property.dataSpecsList"
|
v-model="property.dataSpecsList"
|
||||||
/>
|
/>
|
||||||
<el-form-item v-if="!isStructDataSpecs && !isParams" label="读写类型" prop="property.accessMode">
|
<el-form-item v-if="!isStructDataSpecs && !isParams" label="读写类型" prop="property.accessMode">
|
||||||
<!-- TODO @AI:枚举 -->
|
|
||||||
<el-radio-group v-model="property.accessMode">
|
<el-radio-group v-model="property.accessMode">
|
||||||
<el-radio :label="IoTThingModelAccessModeEnum.READ_WRITE.value">
|
<el-radio
|
||||||
{{ IoTThingModelAccessModeEnum.READ_WRITE.label }}
|
v-for="accessMode in Object.values(IoTThingModelAccessModeEnum)"
|
||||||
</el-radio>
|
:key="accessMode.value"
|
||||||
<el-radio :label="IoTThingModelAccessModeEnum.READ_ONLY.value">
|
:label="accessMode.value"
|
||||||
{{ IoTThingModelAccessModeEnum.READ_ONLY.label }}
|
>
|
||||||
|
{{ accessMode.label }}
|
||||||
</el-radio>
|
</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -118,14 +118,11 @@ const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean; isPara
|
||||||
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<ThingModelProperty>
|
||||||
const getDataTypeOptions2 = computed(() => {
|
const getDataTypeOptions2 = computed(() => {
|
||||||
return !props.isStructDataSpecs
|
if (!props.isStructDataSpecs) {
|
||||||
? getDataTypeOptions()
|
return getDataTypeOptions()
|
||||||
: getDataTypeOptions().filter(
|
}
|
||||||
(item: any) =>
|
const excludedTypes = [IoTDataSpecsDataTypeEnum.STRUCT, IoTDataSpecsDataTypeEnum.ARRAY]
|
||||||
!([IoTDataSpecsDataTypeEnum.STRUCT, IoTDataSpecsDataTypeEnum.ARRAY] as any[]).includes(
|
return getDataTypeOptions().filter((item: any) => !excludedTypes.includes(item.value))
|
||||||
item.value
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}) // 获得数据类型列表
|
}) // 获得数据类型列表
|
||||||
|
|
||||||
/** 属性值的数据类型切换时初始化相关数据 */
|
/** 属性值的数据类型切换时初始化相关数据 */
|
||||||
|
|
@ -158,7 +155,7 @@ const handleChange = (dataType: any) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认选中读写
|
/** 默认选中读写 */
|
||||||
watch(
|
watch(
|
||||||
() => property.value.accessMode,
|
() => property.value.accessMode,
|
||||||
(val: string) => {
|
(val: string) => {
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
prop="service.callType"
|
prop="service.callType"
|
||||||
>
|
>
|
||||||
<el-radio-group v-model="service.callType">
|
<el-radio-group v-model="service.callType">
|
||||||
<!-- TODO @AI:使用 IoTThingModelServiceCallTypeEnum 处理下 -->
|
<el-radio
|
||||||
<el-radio :value="IoTThingModelServiceCallTypeEnum.ASYNC.value">
|
v-for="callType in Object.values(IoTThingModelServiceCallTypeEnum)"
|
||||||
{{ IoTThingModelServiceCallTypeEnum.ASYNC.label }}
|
:key="callType.value"
|
||||||
</el-radio>
|
:value="callType.value"
|
||||||
<el-radio :value="IoTThingModelServiceCallTypeEnum.SYNC.value">
|
>
|
||||||
{{ IoTThingModelServiceCallTypeEnum.SYNC.label }}
|
{{ callType.label }}
|
||||||
</el-radio>
|
</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
@ -46,7 +46,7 @@ const props = defineProps<{ modelValue: any; isStructDataSpecs?: boolean }>()
|
||||||
const emits = defineEmits(['update:modelValue'])
|
const emits = defineEmits(['update:modelValue'])
|
||||||
const service = useVModel(props, 'modelValue', emits) as Ref<ThingModelService>
|
const service = useVModel(props, 'modelValue', emits) as Ref<ThingModelService>
|
||||||
|
|
||||||
// 默认选中,ASYNC 异步
|
/** 默认选中,ASYNC 异步 */
|
||||||
watch(
|
watch(
|
||||||
() => service.value.callType,
|
() => service.value.callType,
|
||||||
(val: string) =>
|
(val: string) =>
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@
|
||||||
<!-- 属性配置 -->
|
<!-- 属性配置 -->
|
||||||
<ThingModelProperty v-model="formData.property" is-struct-data-specs />
|
<ThingModelProperty v-model="formData.property" is-struct-data-specs />
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
|
@ -117,19 +116,16 @@ const submitForm = async () => {
|
||||||
dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
|
dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找是否已有相同 identifier 的项
|
// 新增或修改同 identifier 的参数
|
||||||
const existingIndex = dataSpecsList.value.findIndex(
|
const existingIndex = dataSpecsList.value.findIndex(
|
||||||
(spec) => spec.identifier === data.identifier
|
(spec) => spec.identifier === data.identifier
|
||||||
)
|
)
|
||||||
if (existingIndex > -1) {
|
if (existingIndex > -1) {
|
||||||
// 更新已有项
|
|
||||||
dataSpecsList.value[existingIndex] = item
|
dataSpecsList.value[existingIndex] = item
|
||||||
} else {
|
} else {
|
||||||
// 添加新项
|
|
||||||
dataSpecsList.value.push(item)
|
dataSpecsList.value.push(item)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// 隐藏对话框
|
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
import { isEmpty } from '@/utils/is'
|
import { isEmpty } from '@/utils/is'
|
||||||
|
|
||||||
/** iot 依赖注入 KEY */
|
/** IoT 依赖注入 KEY */
|
||||||
export const IOT_PROVIDE_KEY = {
|
export const IOT_PROVIDE_KEY = {
|
||||||
PRODUCT: 'IOT_PRODUCT'
|
PRODUCT: 'IOT_PRODUCT'
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOT 产品物模型类型枚举类
|
/** IoT 产品物模型类型枚举类 */
|
||||||
export const IoTThingModelTypeEnum = {
|
export const IoTThingModelTypeEnum = {
|
||||||
PROPERTY: 1, // 属性
|
PROPERTY: 1, // 属性
|
||||||
SERVICE: 2, // 服务
|
SERVICE: 2, // 服务
|
||||||
EVENT: 3 // 事件
|
EVENT: 3 // 事件
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
/**
|
/** IoT 设备消息的方法枚举 */
|
||||||
* IoT 设备消息的方法枚举
|
|
||||||
*/
|
|
||||||
export const IotDeviceMessageMethodEnum = {
|
export const IotDeviceMessageMethodEnum = {
|
||||||
// ========== 设备状态 ==========
|
// ========== 设备状态 ==========
|
||||||
STATE_UPDATE: {
|
STATE_UPDATE: {
|
||||||
|
|
@ -57,28 +55,28 @@ export const IotDeviceMessageMethodEnum = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOT 产品物模型类型枚举类
|
// IoT 产品物模型类型枚举类
|
||||||
export const IotThingModelTypeEnum = {
|
export const IotThingModelTypeEnum = {
|
||||||
PROPERTY: 1, // 属性
|
PROPERTY: 1, // 属性
|
||||||
SERVICE: 2, // 服务
|
SERVICE: 2, // 服务
|
||||||
EVENT: 3 // 事件
|
EVENT: 3 // 事件
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOT 产品物模型服务调用方式枚举
|
// IoT 产品物模型服务调用方式枚举
|
||||||
export const IoTThingModelServiceCallTypeEnum = {
|
export const IoTThingModelServiceCallTypeEnum = {
|
||||||
ASYNC: {
|
ASYNC: {
|
||||||
label: '异步调用',
|
label: '异步',
|
||||||
value: 'async'
|
value: 'async'
|
||||||
},
|
},
|
||||||
SYNC: {
|
SYNC: {
|
||||||
label: '同步调用',
|
label: '同步',
|
||||||
value: 'sync'
|
value: 'sync'
|
||||||
}
|
}
|
||||||
} as const
|
} as const
|
||||||
export const getThingModelServiceCallTypeLabel = (value: string): string | undefined =>
|
export const getThingModelServiceCallTypeLabel = (value: string): string | undefined =>
|
||||||
Object.values(IoTThingModelServiceCallTypeEnum).find((type) => type.value === value)?.label
|
Object.values(IoTThingModelServiceCallTypeEnum).find((type) => type.value === value)?.label
|
||||||
|
|
||||||
// IOT 产品物模型事件类型枚举
|
// IoT 产品物模型事件类型枚举
|
||||||
export const IoTThingModelEventTypeEnum = {
|
export const IoTThingModelEventTypeEnum = {
|
||||||
INFO: {
|
INFO: {
|
||||||
label: '信息',
|
label: '信息',
|
||||||
|
|
@ -96,13 +94,13 @@ export const IoTThingModelEventTypeEnum = {
|
||||||
export const getEventTypeLabel = (value: string): string | undefined =>
|
export const getEventTypeLabel = (value: string): string | undefined =>
|
||||||
Object.values(IoTThingModelEventTypeEnum).find((type) => type.value === value)?.label
|
Object.values(IoTThingModelEventTypeEnum).find((type) => type.value === value)?.label
|
||||||
|
|
||||||
// IOT 产品物模型参数是输入参数还是输出参数
|
// IoT 产品物模型参数是输入参数还是输出参数
|
||||||
export const IoTThingModelParamDirectionEnum = {
|
export const IoTThingModelParamDirectionEnum = {
|
||||||
INPUT: 'input', // 输入参数
|
INPUT: 'input', // 输入参数
|
||||||
OUTPUT: 'output' // 输出参数
|
OUTPUT: 'output' // 输出参数
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
// IOT 产品物模型访问模式枚举类
|
// IoT 产品物模型访问模式枚举类
|
||||||
export const IoTThingModelAccessModeEnum = {
|
export const IoTThingModelAccessModeEnum = {
|
||||||
READ_WRITE: {
|
READ_WRITE: {
|
||||||
label: '读写',
|
label: '读写',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue