review:【iot 物联网】场景联动的逻辑

This commit is contained in:
YunaiV
2025-08-04 22:13:17 +08:00
parent 9ca86c292b
commit d74080d6b0
8 changed files with 27 additions and 10 deletions

View File

@ -155,11 +155,13 @@ const addSubGroup = () => {
}
// 检查是否达到最大子组数量限制
// TODO @puhui999最大的数量限制
if (container.value?.length >= maxSubGroups) {
return
}
// 使用 nextTick 确保响应式更新完成后再添加新的子组
// TODO @puhui999这里 nextTick 要不要 await
nextTick(() => {
if (container.value) {
container.value.push([])

View File

@ -1,13 +1,13 @@
<template>
<div class="space-y-16px">
<!-- 触发事件类型选择 -->
<!-- TODO @puhui999事件上报时应该也是 json -->
<el-form-item label="触发事件类型" required>
<el-select
:model-value="triggerType"
@update:model-value="handleTriggerTypeChange"
placeholder="请选择触发事件类型"
class="w-full"
style="width: 100%"
>
<el-option
v-for="option in triggerTypeOptions"

View File

@ -39,7 +39,7 @@
:class="jsonError ? 'text-[var(--el-color-danger)]' : 'text-[var(--el-color-success)]'"
class="text-12px"
>
{{ jsonError || 'JSON格式正确' }}
{{ jsonError || 'JSON 格式正确' }}
</span>
</div>
@ -49,6 +49,7 @@
<el-button size="small" type="primary" plain @click="fillExampleJson">
示例数据
</el-button>
<!-- TODO @puhui999这里的 type 有告警 -->
<el-button size="small" type="default" plain @click="clearParams"> 清空 </el-button>
</div>
</div>
@ -89,9 +90,9 @@
<div class="flex-1">
<div class="text-12px font-500 text-[var(--el-text-color-primary)]">
{{ param.name }}
<el-tag v-if="param.required" size="small" type="danger" class="ml-4px"
>必填</el-tag
>
<el-tag v-if="param.required" size="small" type="danger" class="ml-4px">
必填
</el-tag>
</div>
<div class="text-11px text-[var(--el-text-color-secondary)]">
{{ param.identifier }}
@ -110,11 +111,13 @@
<div class="mt-12px ml-22px">
<div class="text-12px text-[var(--el-text-color-secondary)] mb-6px">
完整JSON格式
完整 JSON 格式
</div>
<pre
class="p-12px bg-[var(--el-fill-color-light)] rounded-4px text-11px text-[var(--el-text-color-primary)] overflow-x-auto border-l-3px border-[var(--el-color-primary)]"
><code>{{ generateExampleJson() }}</code></pre>
>
<code>{{ generateExampleJson() }}</code>
</pre>
</div>
</div>
@ -166,6 +169,8 @@ const localValue = useVModel(props, 'modelValue', emit, {
defaultValue: ''
})
// TODO @puhui999一些注释风格
// 状态
const paramsJson = ref('')
const jsonError = ref('')
@ -192,7 +197,7 @@ const handleParamsChange = () => {
// 额外的参数验证
if (typeof parsed !== 'object' || parsed === null) {
jsonError.value = '参数必须是一个有效的JSON对象'
jsonError.value = '参数必须是一个有效的 JSON 对象'
emit('validate', { valid: false, message: jsonError.value })
return
}
@ -219,8 +224,7 @@ const handleParamsChange = () => {
// 快速填充示例数据
const fillExampleJson = () => {
const exampleData = generateExampleJson()
paramsJson.value = exampleData
paramsJson.value = generateExampleJson()
handleParamsChange()
}
@ -233,6 +237,7 @@ const clearParams = () => {
}
// 工具函数
// TODO @puhui999这里的复用
const getParamTypeName = (dataType: string) => {
const typeMap = {
int: '整数',

View File

@ -146,6 +146,7 @@ const createDefaultActionData = (): ActionFormData => {
}
// 配置常量
// TODO @puhui999去掉最大注释风格改下
const maxActions = 5
// 工具函数

View File

@ -121,6 +121,7 @@ const triggers = useVModel(props, 'triggers', emit)
const triggerTypeOptions = getTriggerTypeOptions()
// 工具函数
// TODO @puhui999这里是不是重复了哈
const getTriggerTypeLabel = (type: number): string => {
const option = triggerTypeOptions.find((opt) => opt.value === type)
return option?.label || '未知类型'

View File

@ -2,6 +2,7 @@
<template>
<div class="w-full">
<!-- TODO @puhui9991设备属性设置时貌似没选属性2服务调用时貌似也没的设置哈 -->
<!-- TODO @puhui999执行器的样式风格需要统一 -->
<el-form-item label="执行类型" required>
<el-select
v-model="localValue"
@ -62,6 +63,7 @@ const emit = defineEmits<Emits>()
const localValue = useVModel(props, 'modelValue', emit)
// 执行器类型选项
// TODO @puhui999我们是不是弱化 icon 和 tag所有组件让整体交互更简洁和一致
const actionTypeOptions = [
{
value: IotRuleSceneActionTypeEnum.DEVICE_PROPERTY_SET,

View File

@ -195,6 +195,7 @@ const emit = defineEmits<{
(e: 'change', value?: string, service?: ThingModelService): void
}>()
// TODO @puhui999这里不用的
const localValue = useVModel(props, 'modelValue', emit)
// 状态
@ -240,6 +241,7 @@ const getCallTypeTag = (callType: string) => {
return callType === 'sync' ? 'primary' : 'success'
}
// TODO @puhui999一些注释风格
const getParamTypeName = (dataType: string) => {
const typeMap = {
int: '整数',

View File

@ -283,6 +283,7 @@ const statistics = ref({
/** 格式化 CRON 表达式显示 */
/** 注:后续可考虑将此功能移至 CRON 组件内部 */
// TODO @puhui999优化这个format
const formatCronExpression = (cron: string): string => {
if (!cron) return ''
@ -418,6 +419,7 @@ const getRuleSceneSummary = (rule: IotRuleSceneDO) => {
const getList = async () => {
loading.value = true
try {
// TODO @puhui999这里的注释优化下
// 调用真实API获取数据
const data = await RuleSceneApi.getRuleScenePage(queryParams)
list.value = data.list
@ -427,6 +429,7 @@ const getList = async () => {
updateStatistics()
} catch (error) {
console.error('获取列表失败:', error)
// TODO @puhui999这里的处理是不是和其他模块一致哈
ElMessage.error('获取列表失败')
// 清空列表数据
@ -506,6 +509,7 @@ const handleDelete = async (id: number) => {
const handleToggleStatus = async (row: IotRuleSceneDO) => {
try {
// 修改状态的二次确认
// TODO @puhui999status 枚举;
const text = row.status === 0 ? '禁用' : '启用'
await message.confirm('确认要' + text + '"' + row.name + '"吗?')
// 发起修改状态