From a5478ffcfe25d6bac87c8035bd6d8735234eecd0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Aug 2025 16:05:48 +0800 Subject: [PATCH] =?UTF-8?q?review=EF=BC=9A=E3=80=90iot=20=E7=89=A9?= =?UTF-8?q?=E8=81=94=E7=BD=91=E3=80=91=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/cron.ts | 40 +++++-------------- src/views/iot/rule/data/index.vue | 2 +- .../iot/rule/scene/form/RuleSceneForm.vue | 23 ++++------- .../scene/form/configs/ConditionConfig.vue | 20 +++------- .../configs/CurrentTimeConditionConfig.vue | 9 +---- .../form/configs/DeviceControlConfig.vue | 10 ++--- .../form/configs/DeviceTriggerConfig.vue | 8 +--- .../form/configs/MainConditionInnerConfig.vue | 9 ++--- .../form/configs/SubConditionGroupConfig.vue | 4 +- .../scene/form/sections/ActionSection.vue | 1 + .../scene/form/sections/TriggerSection.vue | 10 ++--- .../scene/form/selectors/DeviceSelector.vue | 8 ++-- .../scene/form/selectors/OperatorSelector.vue | 3 +- .../scene/form/selectors/ProductSelector.vue | 14 +++---- .../scene/form/selectors/PropertySelector.vue | 11 +++-- src/views/iot/rule/scene/index.vue | 18 +-------- src/views/iot/utils/constants.ts | 23 +++++++---- 17 files changed, 72 insertions(+), 141 deletions(-) diff --git a/src/utils/cron.ts b/src/utils/cron.ts index 886fc847..ee132f00 100644 --- a/src/utils/cron.ts +++ b/src/utils/cron.ts @@ -105,9 +105,7 @@ export const CRON_PRESETS = { /** CRON 表达式工具类 */ export class CronUtils { - /** - * 验证 CRON 表达式格式 - */ + /** 验证 CRON 表达式格式 */ static validate(cronExpression: string): boolean { if (!cronExpression || typeof cronExpression !== 'string') { return false @@ -125,9 +123,7 @@ export class CronUtils { return parts.every((part) => cronRegex.test(part)) } - /** - * 解析单个 CRON 字段 - */ + /** 解析单个 CRON 字段 */ static parseField( fieldValue: string, fieldType: CronFieldType, @@ -206,9 +202,7 @@ export class CronUtils { return field } - /** - * 解析完整的 CRON 表达式 - */ + /** 解析完整的 CRON 表达式 */ static parse(cronExpression: string): ParsedCronExpression { const result: ParsedCronExpression = { second: { type: 'any', values: [], original: '*', description: '每秒' }, @@ -259,9 +253,7 @@ export class CronUtils { return result } - /** - * 生成 CRON 表达式的可读描述 - */ + /** 生成 CRON 表达式的可读描述 */ static generateDescription(parsed: ParsedCronExpression): string { const parts: string[] = [] @@ -305,9 +297,7 @@ export class CronUtils { return parts.length > 0 ? parts.join(' ') : '自定义时间规则' } - /** - * 格式化 CRON 表达式为可读文本 - */ + /** 格式化 CRON 表达式为可读文本 */ static format(cronExpression: string): string { if (!cronExpression) return '' @@ -315,9 +305,7 @@ export class CronUtils { return parsed.isValid ? parsed.description : cronExpression } - /** - * 获取预设的 CRON 表达式列表 - */ + /** 获取预设的 CRON 表达式列表 */ static getPresets() { return Object.entries(CRON_PRESETS).map(([key, value]) => ({ label: this.format(value), @@ -326,9 +314,7 @@ export class CronUtils { })) } - /** - * 计算 CRON 表达式的下次执行时间 - */ + /** 计算 CRON 表达式的下次执行时间 */ static getNextExecutionTime(cronExpression: string, fromDate?: Date): Date | null { const parsed = this.parse(cronExpression) if (!parsed.isValid) { @@ -402,9 +388,7 @@ export class CronUtils { return new Date(now.getTime() + 60000) // 1分钟后 } - /** - * 获取 CRON 表达式的执行频率描述 - */ + /** 获取 CRON 表达式的执行频率描述 */ static getFrequencyDescription(cronExpression: string): string { const parsed = this.parse(cronExpression) if (!parsed.isValid) { @@ -435,9 +419,7 @@ export class CronUtils { return '按计划执行' } - /** - * 检查 CRON 表达式是否会在指定时间执行 - */ + /** 检查 CRON 表达式是否会在指定时间执行 */ static willExecuteAt(cronExpression: string, targetDate: Date): boolean { const parsed = this.parse(cronExpression) if (!parsed.isValid) { @@ -462,9 +444,7 @@ export class CronUtils { ) } - /** - * 检查字段值是否匹配 - */ + /** 检查字段值是否匹配 */ private static fieldMatches(field: ParsedCronField, value: number): boolean { if (field.type === 'any') { return true diff --git a/src/views/iot/rule/data/index.vue b/src/views/iot/rule/data/index.vue index 123397ee..8c887593 100644 --- a/src/views/iot/rule/data/index.vue +++ b/src/views/iot/rule/data/index.vue @@ -14,7 +14,7 @@ import RuleIndex from './rule/index.vue' import SinkIndex from './sink/index.vue' /** IoT 数据流转 */ -defineOptions({ name: 'IotData' }) +defineOptions({ name: 'IoTDataRule' }) const activeTab = ref('rule') diff --git a/src/views/iot/rule/scene/form/RuleSceneForm.vue b/src/views/iot/rule/scene/form/RuleSceneForm.vue index 09a31657..22ba268e 100644 --- a/src/views/iot/rule/scene/form/RuleSceneForm.vue +++ b/src/views/iot/rule/scene/form/RuleSceneForm.vue @@ -215,7 +215,6 @@ const validateActions = (_rule: any, value: any, callback: any) => { } const formRules = reactive({ - // 表单校验规则 name: [ { required: true, message: '场景名称不能为空', trigger: 'blur' }, { type: 'string', min: 1, max: 50, message: '场景名称长度应在1-50个字符之间', trigger: 'blur' } @@ -234,17 +233,13 @@ const formRules = reactive({ ], triggers: [{ required: true, validator: validateTriggers, trigger: 'change' }], actions: [{ required: true, validator: validateActions, trigger: 'change' }] -}) +}) // 表单校验规则 const submitLoading = ref(false) // 提交加载状态 const isEdit = ref(false) // 是否为编辑模式 +const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则')) // 抽屉标题 -// 计算属性:抽屉标题 -const drawerTitle = computed(() => (isEdit.value ? '编辑场景联动规则' : '新增场景联动规则')) - -/** - * 提交表单 - */ +/** 提交表单 */ const handleSubmit = async () => { // 校验表单 if (!formRef.value) return @@ -275,16 +270,12 @@ const handleSubmit = async () => { } } -/** - * 处理抽屉关闭事件 - */ +/** 处理抽屉关闭事件 */ const handleClose = () => { drawerVisible.value = false } -/** - * 初始化表单数据 - */ +/** 初始化表单数据 */ const initFormData = () => { if (props.ruleScene) { // 编辑模式:数据结构已对齐,直接使用后端数据 @@ -316,7 +307,7 @@ const initFormData = () => { } } -// 监听抽屉显示 +/** 监听抽屉显示 */ watch(drawerVisible, async (visible) => { if (visible) { initFormData() @@ -326,7 +317,7 @@ watch(drawerVisible, async (visible) => { } }) -// 监听编辑数据变化 +/** 监听编辑数据变化 */ watch( () => props.ruleScene, () => { diff --git a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue index f4d36d8f..36dc2f5a 100644 --- a/src/views/iot/rule/scene/form/configs/ConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/ConditionConfig.vue @@ -183,14 +183,12 @@ const condition = useVModel(props, 'modelValue', emit) const propertyType = ref('string') // 属性类型 const propertyConfig = ref(null) // 属性配置 - -// 计算属性:判断是否为设备相关条件 const isDeviceCondition = computed(() => { return ( condition.value.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_STATUS || condition.value.type === IotRuleSceneTriggerConditionTypeEnum.DEVICE_PROPERTY ) -}) +}) // 计算属性:判断是否为设备相关条件 /** * 更新条件字段 @@ -240,20 +238,14 @@ const handleConditionTypeChange = (type: number) => { condition.value.param = '' } -/** - * 处理产品变化事件 - * @param _ 产品ID(未使用) - */ +/** 处理产品变化事件 */ const handleProductChange = (_: number) => { // 产品变化时清空设备和属性 condition.value.deviceId = undefined condition.value.identifier = '' } -/** - * 处理设备变化事件 - * @param _ 设备ID(未使用) - */ +/** 处理设备变化事件 */ const handleDeviceChange = (_: number) => { // 设备变化时清空属性 condition.value.identifier = '' @@ -268,13 +260,11 @@ const handlePropertyChange = (propertyInfo: { type: string; config: any }) => { propertyConfig.value = propertyInfo.config // 重置操作符和值 - condition.value.operator = '=' + condition.value.operator = IotRuleSceneTriggerConditionParameterOperatorEnum.EQUALS.value condition.value.param = '' } -/** - * 处理操作符变化事件 - */ +/** 处理操作符变化事件 */ const handleOperatorChange = () => { // 重置值 condition.value.param = '' diff --git a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue index b9f477d3..9d304b70 100644 --- a/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue +++ b/src/views/iot/rule/scene/form/configs/CurrentTimeConditionConfig.vue @@ -1,13 +1,6 @@