feat(iot): 优化 rule scene 的代码风格
parent
538d04a380
commit
5607f23322
|
|
@ -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 @AI:那就修复这个。后端增加接口,antd 和 vue3 + ep 都改;
|
||||||
/** 加载告警配置列表 */
|
/** 加载告警配置列表 */
|
||||||
async function loadAlertConfigs() {
|
async function loadAlertConfigs() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -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 @AI:change 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 @AI:JsonParamsInput 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 格式的事件参数"
|
||||||
|
|
|
||||||
|
|
@ -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 @AI:defineOptions 这种,和上面这种注释,是不是可以去掉?(iot 里,其它的看看也检查下。)
|
|
||||||
defineOptions({ name: 'TimerConditionGroupConfig' });
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue?: TriggerCondition[][];
|
modelValue?: TriggerCondition[][];
|
||||||
}>();
|
}>();
|
||||||
|
|
|
||||||
|
|
@ -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 @AI:1)这种注释,可以简化成 /** */ 单行么?;2)vue3 + 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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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 @AI:不要这种简单的缩写,p 是 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({
|
||||||
|
|
|
||||||
|
|
@ -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 @AI:1)枚举;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),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue