From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/iot/thingmodel/ThingModelInputOutputParam.vue | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 151 insertions(+), 0 deletions(-)
diff --git a/src/views/iot/thingmodel/ThingModelInputOutputParam.vue b/src/views/iot/thingmodel/ThingModelInputOutputParam.vue
new file mode 100644
index 0000000..04bc950
--- /dev/null
+++ b/src/views/iot/thingmodel/ThingModelInputOutputParam.vue
@@ -0,0 +1,151 @@
+<!-- 浜у搧鐨勭墿妯″瀷琛ㄥ崟锛坋vent銆乻ervice 椤归噷鐨勫弬鏁帮級 -->
+<template>
+ <div
+ v-for="(item, index) in thingModelParams"
+ :key="index"
+ class="w-1/1 param-item flex justify-between px-10px mb-10px"
+ >
+ <span>鍙傛暟鍚嶇О锛歿{ item.name }}</span>
+ <div class="btn">
+ <el-button link type="primary" @click="openParamForm(item)">缂栬緫</el-button>
+ <el-divider direction="vertical" />
+ <el-button link type="danger" @click="deleteParamItem(index)">鍒犻櫎</el-button>
+ </div>
+ </div>
+ <el-button link type="primary" @click="openParamForm(null)">+鏂板鍙傛暟</el-button>
+
+ <!-- param 琛ㄥ崟 -->
+ <Dialog v-model="dialogVisible" title="鏂板鍙傛暟" append-to-body>
+ <el-form
+ ref="paramFormRef"
+ v-loading="formLoading"
+ :model="formData"
+ :rules="ThingModelFormRules"
+ label-width="100px"
+ >
+ <el-form-item label="鍙傛暟鍚嶇О" prop="name">
+ <el-input v-model="formData.name" placeholder="璇疯緭鍏ュ姛鑳藉悕绉�" />
+ </el-form-item>
+ <el-form-item label="鏍囪瘑绗�" prop="identifier">
+ <el-input v-model="formData.identifier" placeholder="璇疯緭鍏ユ爣璇嗙" />
+ </el-form-item>
+ <!-- 灞炴�ч厤缃� -->
+ <ThingModelProperty v-model="formData.property" is-params />
+ </el-form>
+ <template #footer>
+ <el-button :disabled="formLoading" type="primary" @click="submitForm">纭� 瀹�</el-button>
+ <el-button @click="dialogVisible = false">鍙� 娑�</el-button>
+ </template>
+ </Dialog>
+</template>
+
+<script lang="ts" setup>
+import { useVModel } from '@vueuse/core'
+import ThingModelProperty from './ThingModelProperty.vue'
+import { isEmpty } from '@/utils/is'
+import { IoTDataSpecsDataTypeEnum } from '@/views/iot/utils/constants'
+import { ThingModelFormRules } from '@/api/iot/thingmodel'
+
+/** 杈撳叆杈撳嚭鍙傛暟閰嶇疆缁勪欢 */
+defineOptions({ name: 'ThingModelInputOutputParam' })
+
+const props = defineProps<{ modelValue: any; direction: string }>()
+const emits = defineEmits(['update:modelValue'])
+const thingModelParams = useVModel(props, 'modelValue', emits) as Ref<any[]>
+const dialogVisible = ref(false) // 寮圭獥鐨勬槸鍚﹀睍绀�
+const formLoading = ref(false) // 琛ㄥ崟鐨勫姞杞戒腑锛�1锛変慨鏀规椂鐨勬暟鎹姞杞斤紱2锛夋彁浜ょ殑鎸夐挳绂佺敤
+const paramFormRef = ref() // 琛ㄥ崟 ref
+const formData = ref<any>({
+ dataType: IoTDataSpecsDataTypeEnum.INT,
+ property: {
+ dataType: IoTDataSpecsDataTypeEnum.INT,
+ dataSpecs: {
+ dataType: IoTDataSpecsDataTypeEnum.INT
+ }
+ }
+})
+
+/** 鎵撳紑 param 琛ㄥ崟 */
+const openParamForm = (val: any) => {
+ dialogVisible.value = true
+ resetForm()
+ if (isEmpty(val)) {
+ return
+ }
+ // 缂栬緫鏃跺洖鏄炬暟鎹�
+ formData.value = {
+ identifier: val.identifier,
+ name: val.name,
+ description: val.description,
+ property: {
+ dataType: val.dataType,
+ dataSpecs: val.dataSpecs,
+ dataSpecsList: val.dataSpecsList
+ }
+ }
+}
+
+/** 鍒犻櫎 param 椤� */
+const deleteParamItem = (index: number) => {
+ thingModelParams.value.splice(index, 1)
+}
+
+/** 娣诲姞鍙傛暟 */
+const submitForm = async () => {
+ // 鍒濆鍖栧弬鏁板垪琛�
+ if (isEmpty(thingModelParams.value)) {
+ thingModelParams.value = []
+ }
+ // 鏍¢獙鍙傛暟
+ await paramFormRef.value.validate()
+ try {
+ // 鏋勫缓鏁版嵁瀵硅薄
+ const data = unref(formData)
+ const item = {
+ identifier: data.identifier,
+ name: data.name,
+ description: data.description,
+ dataType: data.property.dataType,
+ paraOrder: 0, // TODO @puhui999: 鍏堝啓姝婚粯璁ょ湅鐪嬪悗缁�
+ direction: props.direction,
+ dataSpecs:
+ !!data.property.dataSpecs && Object.keys(data.property.dataSpecs).length > 1
+ ? data.property.dataSpecs
+ : undefined,
+ dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
+ }
+
+ // 鏂板鎴栦慨鏀瑰悓 identifier 鐨勫弬鏁�
+ const existingIndex = thingModelParams.value.findIndex(
+ (spec) => spec.identifier === data.identifier
+ )
+ if (existingIndex > -1) {
+ thingModelParams.value[existingIndex] = item
+ } else {
+ thingModelParams.value.push(item)
+ }
+ } finally {
+ dialogVisible.value = false
+ }
+}
+
+/** 閲嶇疆琛ㄥ崟 */
+const resetForm = () => {
+ formData.value = {
+ dataType: IoTDataSpecsDataTypeEnum.INT,
+ property: {
+ dataType: IoTDataSpecsDataTypeEnum.INT,
+ dataSpecs: {
+ dataType: IoTDataSpecsDataTypeEnum.INT
+ }
+ }
+ }
+ paramFormRef.value?.resetFields()
+}
+</script>
+
+<style lang="scss" scoped>
+.param-item {
+ background-color: #e4f2fd;
+}
+</style>
--
Gitblit v1.8.0