perf: 【IoT 物联网】场景联动执行器和触发器的参数值类型都调整为了字符串类型

pull/806/head
puhui999 2025-08-05 22:12:19 +08:00
parent d81c544ad9
commit 9f3eb14a0f
2 changed files with 40 additions and 82 deletions

View File

@ -97,7 +97,7 @@
<!-- 服务调用参数配置 -->
<JsonParamsInput
v-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE"
v-model="conditionValueAsString"
v-model="condition.value"
type="service"
:config="serviceConfig"
placeholder="请输入JSON格式的服务参数"
@ -106,7 +106,7 @@
<!-- 事件上报参数配置 -->
<JsonParamsInput
v-else-if="triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST"
v-model="conditionValueAsString"
v-model="condition.value"
type="event"
:config="eventConfig"
placeholder="请输入JSON格式的事件参数"
@ -257,23 +257,6 @@ const eventConfig = computed(() => {
return undefined
})
// JsonParamsInput
const conditionValueAsString = computed({
get: () => {
const value = condition.value.value
if (value === null || value === undefined) {
return ''
}
if (typeof value === 'object') {
return JSON.stringify(value, null, 2)
}
return String(value)
},
set: (newValue: string) => {
condition.value.value = newValue
}
})
//
// TODO @puhui999
const getTriggerTypeText = (type: number) => {

View File

@ -189,12 +189,15 @@ const jsonError = ref('')
//
const hasConfig = computed(() => {
return !!(
props.config?.service ||
props.config?.event ||
props.config?.properties ||
props.config?.custom
)
// TODO @puhui999:
console.log(props.config)
// return !!(
// props.config?.service ||
// props.config?.event ||
// props.config?.properties ||
// props.config?.custom
// )
return true
})
const paramsList = computed(() => {
@ -440,44 +443,26 @@ const generateExampleJson = () => {
return JSON.stringify(example, null, 2)
}
//
const isInitialized = ref(false)
//
const initializeData = () => {
if (isInitialized.value) return
if (localValue.value) {
try {
// modelValue 使
if (localValue.value.trim()) {
try {
// JSON
const parsed = JSON.parse(localValue.value)
paramsJson.value = JSON.stringify(parsed, null, 2)
} catch {
// JSON使
paramsJson.value = localValue.value
}
} else {
paramsJson.value = ''
}
jsonError.value = ''
} catch (error) {
console.error('初始化参数失败:', error)
jsonError.value = '初始参数格式错误'
}
//
const handleDataDisplay = (value: string) => {
if (!value || !value.trim()) {
paramsJson.value = ''
jsonError.value = ''
return
}
isInitialized.value = true
try {
// JSON
const parsed = JSON.parse(value)
paramsJson.value = JSON.stringify(parsed, null, 2)
jsonError.value = ''
} catch {
// JSON使
paramsJson.value = value
jsonError.value = ''
}
}
//
onMounted(() => {
initializeData()
})
//
watch(
() => localValue.value,
@ -485,33 +470,23 @@ watch(
//
if (newValue === oldValue) return
try {
let newJsonString = ''
if (newValue && newValue.trim()) {
try {
// JSON
const parsed = JSON.parse(newValue)
newJsonString = JSON.stringify(parsed, null, 2)
} catch {
// JSON使
newJsonString = newValue
}
}
// JSON
if (newJsonString !== paramsJson.value) {
paramsJson.value = newJsonString
jsonError.value = ''
}
} catch (error) {
console.error('数据回显失败:', error)
jsonError.value = '数据格式错误'
}
// 使 nextTick tick
nextTick(() => {
handleDataDisplay(newValue || '')
})
},
{ immediate: true }
)
//
onMounted(() => {
nextTick(() => {
if (localValue.value) {
handleDataDisplay(localValue.value)
}
})
})
//
watch(
() => props.config,