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); 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() { async function loadAlertConfigs() {
loading.value = true; loading.value = true;

View File

@ -52,8 +52,7 @@ const paramsValue = computed({
}, },
set: (value: string) => { set: (value: string) => {
// JSON // JSON
// TODO @AI linter action.value.params = (value.trim() || '') as any;
action.value.params = value.trim() || '';
}, },
}); });
@ -82,8 +81,8 @@ function handleProductChange(productId?: number) {
if (action.value.productId !== productId) { if (action.value.productId !== productId) {
action.value.deviceId = undefined; action.value.deviceId = undefined;
action.value.identifier = undefined; // action.value.identifier = undefined; //
// TODO @AI linter // TODO DONE @AI linter
action.value.params = ''; // action.value.params = '' as any; //
selectedService.value = null; // selectedService.value = null; //
serviceList.value = []; // serviceList.value = []; //
} }
@ -105,8 +104,8 @@ function handleProductChange(productId?: number) {
function handleDeviceChange(deviceId?: number) { function handleDeviceChange(deviceId?: number) {
// //
if (action.value.deviceId !== deviceId) { if (action.value.deviceId !== deviceId) {
// TODO @AI linter // TODO DONE @AI linter
action.value.params = ''; // action.value.params = '' as any; //
} }
} }
@ -121,16 +120,16 @@ function handleServiceChange(serviceIdentifier?: any) {
selectedService.value = service; selectedService.value = service;
// //
action.value.params = ''; action.value.params = '' as any;
// //
if (service && service.inputParams && service.inputParams.length > 0) { if (service && service.inputParams && service.inputParams.length > 0) {
const defaultParams = {}; const defaultParams: Record<string, any> = {};
service.inputParams.forEach((param) => { service.inputParams.forEach((param) => {
defaultParams[param.identifier] = getDefaultValueForParam(param); defaultParams[param.identifier!] = getDefaultValueForParam(param);
}); });
// JSON // 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 * @param productId 产品ID
* @returns 物模型TSL数据 * @returns 物模型TSL数据
*/ */
async function getThingModelTSL(productId: number) { async function getThingModelTSL(productId: number): Promise<any> {
if (!productId) return null; if (!productId) return null;
try { try {
@ -164,7 +163,7 @@ async function loadThingModelProperties(productId: number) {
loadingThingModel.value = true; loadingThingModel.value = true;
const tslData = await getThingModelTSL(productId); const tslData = await getThingModelTSL(productId);
// TODO @AI linter // TODO DONE @AI linter
if (!tslData?.properties) { if (!tslData?.properties) {
thingModelProperties.value = []; thingModelProperties.value = [];
return; return;
@ -199,13 +198,13 @@ async function loadServiceList(productId: number) {
loadingServices.value = true; loadingServices.value = true;
const tslData = await getThingModelTSL(productId); const tslData = await getThingModelTSL(productId);
// TODO @AI linter // TODO DONE @AI linter
if (!tslData?.services) { if (!tslData?.services) {
serviceList.value = []; serviceList.value = [];
return; return;
} }
// TODO @AI linter // TODO DONE @AI linter
serviceList.value = tslData.services; serviceList.value = tslData.services;
} catch (error) { } catch (error) {
console.error('加载服务列表失败:', error); console.error('加载服务列表失败:', error);

View File

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

View File

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

View File

@ -12,10 +12,6 @@ import { IotRuleSceneTriggerTypeEnum } from '#/views/iot/utils/constants';
import SubConditionGroupConfig from './sub-condition-group-config.vue'; import SubConditionGroupConfig from './sub-condition-group-config.vue';
/** 定时触发器条件组配置组件 */
// TODO @AIdefineOptions iot
defineOptions({ name: 'TimerConditionGroupConfig' });
const props = defineProps<{ const props = defineProps<{
modelValue?: TriggerCondition[][]; modelValue?: TriggerCondition[][];
}>(); }>();

View File

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

View File

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

View File

@ -69,10 +69,8 @@ const propertyGroups = computed(() => {
if (props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST) { if (props.triggerType === IotRuleSceneTriggerTypeEnum.DEVICE_PROPERTY_POST) {
groups.push({ groups.push({
label: THING_MODEL_GROUP_LABELS.PROPERTY, label: THING_MODEL_GROUP_LABELS.PROPERTY,
// TODO @AIp property
// TODO @AI linter
options: propertyList.value.filter( options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.PROPERTY, (property: any) => property.type === IoTThingModelTypeEnum.PROPERTY,
), ),
}); });
} }
@ -81,7 +79,7 @@ const propertyGroups = computed(() => {
groups.push({ groups.push({
label: THING_MODEL_GROUP_LABELS.EVENT, label: THING_MODEL_GROUP_LABELS.EVENT,
options: propertyList.value.filter( options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.EVENT, (property: any) => property.type === IoTThingModelTypeEnum.EVENT,
), ),
}); });
} }
@ -90,7 +88,7 @@ const propertyGroups = computed(() => {
groups.push({ groups.push({
label: THING_MODEL_GROUP_LABELS.SERVICE, label: THING_MODEL_GROUP_LABELS.SERVICE,
options: propertyList.value.filter( options: propertyList.value.filter(
(p) => p.type === IoTThingModelTypeEnum.SERVICE, (property: any) => property.type === IoTThingModelTypeEnum.SERVICE,
), ),
}); });
} }
@ -156,6 +154,7 @@ function parseThingModelData() {
return; return;
} }
// //
// TODO @AI linter
if (tsl.properties && Array.isArray(tsl.properties)) { if (tsl.properties && Array.isArray(tsl.properties)) {
tsl.properties.forEach((prop) => { tsl.properties.forEach((prop) => {
properties.push({ properties.push({
@ -174,6 +173,7 @@ function parseThingModelData() {
} }
// //
// TODO @AI linter
if (tsl.events && Array.isArray(tsl.events)) { if (tsl.events && Array.isArray(tsl.events)) {
tsl.events.forEach((event) => { tsl.events.forEach((event) => {
properties.push({ properties.push({

View File

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