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

pull/345/head
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 @AIantd 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 @AIp 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),