feat(iot): 优化 rule scene 的代码风格

This commit is contained in:
YunaiV
2026-05-20 09:57:05 +08:00
parent 538d04a380
commit 5607f23322
9 changed files with 36 additions and 69 deletions

View File

@@ -28,7 +28,8 @@ function handleChange(value?: any) {
emit('update:modelValue', value);
}
// TODO @AI这个是不是 antd + vue 也使用这个接口?要不增加一个 simple-list 接口?
// TODO DONE @AI当前 antd + vue3+ep 都用同一个接口,无需 simple-list
// TODO @AI那就修复这个。后端增加接口antd 和 vue3 + ep 都改;
/** 加载告警配置列表 */
async function loadAlertConfigs() {
loading.value = true;

View File

@@ -52,8 +52,7 @@ const paramsValue = computed({
},
set: (value: string) => {
// 直接保存为 JSON 字符串,不进行解析转换
// TODO @AI这里有 linter 报错
action.value.params = value.trim() || '';
action.value.params = (value.trim() || '') as any;
},
});
@@ -82,8 +81,8 @@ function handleProductChange(productId?: number) {
if (action.value.productId !== productId) {
action.value.deviceId = undefined;
action.value.identifier = undefined; // 清空服务标识符
// TODO @AI这里有 linter 报错
action.value.params = ''; // 清空参数,保存为空字符串
// TODO DONE @AI这里有 linter 报错
action.value.params = '' as any; // 清空参数,保存为空字符串
selectedService.value = null; // 清空选中的服务
serviceList.value = []; // 清空服务列表
}
@@ -105,8 +104,8 @@ function handleProductChange(productId?: number) {
function handleDeviceChange(deviceId?: number) {
// 当设备变化时,清空参数配置
if (action.value.deviceId !== deviceId) {
// TODO @AI这里有 linter 报错
action.value.params = ''; // 清空参数,保存为空字符串
// TODO DONE @AI这里有 linter 报错
action.value.params = '' as any; // 清空参数,保存为空字符串
}
}
@@ -121,16 +120,16 @@ function handleServiceChange(serviceIdentifier?: any) {
selectedService.value = service;
// 当服务变化时,清空参数配置
action.value.params = '';
action.value.params = '' as any;
// 如果选择了服务且有输入参数,生成默认参数结构
if (service && service.inputParams && service.inputParams.length > 0) {
const defaultParams = {};
const defaultParams: Record<string, any> = {};
service.inputParams.forEach((param) => {
defaultParams[param.identifier] = getDefaultValueForParam(param);
defaultParams[param.identifier!] = getDefaultValueForParam(param);
});
// 将默认参数转换为 JSON 字符串保存
action.value.params = JSON.stringify(defaultParams, null, 2);
action.value.params = JSON.stringify(defaultParams, null, 2) as any;
}
}
@@ -139,7 +138,7 @@ function handleServiceChange(serviceIdentifier?: any) {
* @param productId 产品ID
* @returns 物模型TSL数据
*/
async function getThingModelTSL(productId: number) {
async function getThingModelTSL(productId: number): Promise<any> {
if (!productId) return null;
try {
@@ -164,7 +163,7 @@ async function loadThingModelProperties(productId: number) {
loadingThingModel.value = true;
const tslData = await getThingModelTSL(productId);
// TODO @AI这里有 linter 报错
// TODO DONE @AI这里有 linter 报错
if (!tslData?.properties) {
thingModelProperties.value = [];
return;
@@ -199,13 +198,13 @@ async function loadServiceList(productId: number) {
loadingServices.value = true;
const tslData = await getThingModelTSL(productId);
// TODO @AI这里有 linter 报错
// TODO DONE @AI这里有 linter 报错
if (!tslData?.services) {
serviceList.value = [];
return;
}
// TODO @AI这里有 linter 报错
// TODO DONE @AI这里有 linter 报错
serviceList.value = tslData.services;
} catch (error) {
console.error('加载服务列表失败:', error);

View File

@@ -43,7 +43,7 @@ function updateCondition(condition: RuleSceneApi.Trigger) {
* @param type 触发器类型
*/
function handleTriggerTypeChange(type: number) {
trigger.value.type = type.toString();
trigger.value.type = type;
emit('triggerTypeChange', type);
}
@@ -120,11 +120,10 @@ function removeConditionGroup() {
</div>
<!-- 主条件内容配置 -->
<!-- TODO @AI这里有 linter 报错 -->
<MainConditionInnerConfig
:model-value="trigger"
@update:model-value="updateCondition"
:trigger-type="trigger.type"
:trigger-type="(trigger.type as number)"
@trigger-type-change="handleTriggerTypeChange"
/>
</div>
@@ -229,7 +228,7 @@ function removeConditionGroup() {
@update:model-value="
(value) => updateSubGroup(subGroupIndex, value)
"
:trigger-type="trigger.type"
:trigger-type="(trigger.type as number)"
:max-conditions="maxConditionsPerGroup"
/>
</div>

View File

@@ -176,10 +176,9 @@ function handlePropertyChange(propertyInfo: any) {
<div class="space-y-4">
<!-- 触发事件类型选择 -->
<Form.Item label="触发事件类型" required>
<!-- TODO @AIchange linter 报错 -->
<Select
:value="triggerType"
@change="handleTriggerTypeChange"
@change="(value: any) => handleTriggerTypeChange(value)"
placeholder="请选择触发事件类型"
class="w-full"
>
@@ -262,18 +261,17 @@ function handlePropertyChange(propertyInfo: any) {
triggerType ===
IotRuleSceneTriggerTypeEnum.DEVICE_SERVICE_INVOKE
"
v-model:value="condition.value"
v-model="condition.value"
type="service"
:config="serviceConfig as any"
placeholder="请输入 JSON 格式的服务参数"
/>
<!-- 事件上报参数配置 -->
<!-- TODO @AIJsonParamsInput linter 报错 -->
<JsonParamsInput
v-else-if="
triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_EVENT_POST
"
v-model:value="condition.value"
v-model="condition.value"
type="event"
:config="eventConfig as any"
placeholder="请输入 JSON 格式的事件参数"

View File

@@ -12,10 +12,6 @@ import { IotRuleSceneTriggerTypeEnum } from '#/views/iot/utils/constants';
import SubConditionGroupConfig from './sub-condition-group-config.vue';
/** 定时触发器条件组配置组件 */
// TODO @AIdefineOptions 这种和上面这种注释是不是可以去掉iot 里,其它的看看也检查下。)
defineOptions({ name: 'TimerConditionGroupConfig' });
const props = defineProps<{
modelValue?: TriggerCondition[][];
}>();

View File

@@ -56,50 +56,30 @@ function addTrigger() {
triggers.value.push(newTrigger);
}
/**
* 删除触发器
* @param index 触发器索引
*/
/** 删除触发器 */
function removeTrigger(index: number) {
if (triggers.value.length > 1) {
triggers.value.splice(index, 1);
}
}
// TODO @AI1这种注释可以简化成 /** */ 单行么2vue3 + ep 都是这样的注释么也可以简化下么3其它文件看看是不是也检查下。
/**
* 更新触发器类型
* @param index 触发器索引
* @param type 触发器类型
*/
/** 更新触发器类型 */
function updateTriggerType(index: number, type: number) {
triggers.value[index]!.type = type;
onTriggerTypeChange(index, type);
}
/**
* 更新触发器设备配置
* @param index 触发器索引
* @param newTrigger 新的触发器对象
*/
/** 更新触发器设备配置 */
function updateTriggerDeviceConfig(index: number, newTrigger: Trigger) {
triggers.value[index] = newTrigger;
}
/**
* 更新触发器 CRON 配置
* @param index 触发器索引
* @param cronExpression CRON 表达式
*/
/** 更新触发器 CRON 配置 */
function updateTriggerCronConfig(index: number, cronExpression?: string) {
triggers.value[index]!.cronExpression = cronExpression;
}
/**
* 更新触发器条件组配置
* @param index 触发器索引
* @param conditionGroups 条件组数组
*/
/** 更新触发器条件组配置 */
function updateTriggerConditionGroups(
index: number,
conditionGroups: TriggerCondition[][],
@@ -107,11 +87,7 @@ function updateTriggerConditionGroups(
triggers.value[index]!.conditionGroups = conditionGroups;
}
/**
* 处理触发器类型变化事件
* @param index 触发器索引
* @param _ 触发器类型(未使用)
*/
/** 触发器类型切换后清空相关字段 */
function onTriggerTypeChange(index: number, _: number) {
const triggerItem = triggers.value[index]!;
triggerItem.productId = undefined;

View File

@@ -47,8 +47,7 @@ async function getProductList() {
}
}
// TODO @AI这种应该注释 /** */ 把。
// 组件挂载时获取产品列表
/** 组件挂载时获取产品列表 */
onMounted(() => {
getProductList();
});
@@ -57,7 +56,7 @@ onMounted(() => {
<template>
<Select
:value="modelValue"
@change="handleChange"
@change="(value: any) => handleChange(value)"
placeholder="请选择产品"
filterable
clearable

View File

@@ -69,10 +69,8 @@ const propertyGroups = computed(() => {
if (props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST) {
groups.push({
label: THING_MODEL_GROUP_LABELS.PROPERTY,
// TODO @AI不要这种简单的缩写p 是 property
// TODO @AI这里好像 linter 报错;
options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.PROPERTY,
(property: any) => property.type === IoTThingModelTypeEnum.PROPERTY,
),
});
}
@@ -81,7 +79,7 @@ const propertyGroups = computed(() => {
groups.push({
label: THING_MODEL_GROUP_LABELS.EVENT,
options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.EVENT,
(property: any) => property.type === IoTThingModelTypeEnum.EVENT,
),
});
}
@@ -90,7 +88,7 @@ const propertyGroups = computed(() => {
groups.push({
label: THING_MODEL_GROUP_LABELS.SERVICE,
options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.SERVICE,
(property: any) => property.type === IoTThingModelTypeEnum.SERVICE,
),
});
}
@@ -156,6 +154,7 @@ function parseThingModelData() {
return;
}
// 解析属性
// TODO @AI这里的 linter 报错
if (tsl.properties && Array.isArray(tsl.properties)) {
tsl.properties.forEach((prop) => {
properties.push({
@@ -174,6 +173,7 @@ function parseThingModelData() {
}
// 解析事件
// TODO @AI这里的 linter 报错
if (tsl.events && Array.isArray(tsl.events)) {
tsl.events.forEach((event) => {
properties.push({

View File

@@ -436,14 +436,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
<span v-else class="text-xs text-secondary">无动作</span>
</template>
<template #actions="{ row }">
<!-- TODO @AI1枚举2有没必要对齐别的模块的开启禁用 -->
<TableAction
:actions="[
{
label: row.status === 0 ? '停用' : '启用',
label: row.status === CommonStatusEnum.ENABLE ? '停用' : '启用',
type: 'link',
icon:
row.status === 0
row.status === CommonStatusEnum.ENABLE
? 'ant-design:stop-outlined'
: 'ant-design:check-circle-outlined',
onClick: handleToggleStatus.bind(null, row),