review:【antd】【iot】数据流转

This commit is contained in:
YunaiV
2025-11-21 11:35:39 +08:00
parent f650d44194
commit 80b4a16dc4
9 changed files with 25 additions and 69 deletions

View File

@@ -3,7 +3,7 @@ import type { PageParam, PageResult } from '@vben/request';
import { requestClient } from '#/api/request'; import { requestClient } from '#/api/request';
export namespace RuleSceneApi { export namespace RuleSceneApi {
/** IoT 场景联动规则 VO */ /** 场景联动规则 */
export interface SceneRule { export interface SceneRule {
id?: number; id?: number;
name: string; name: string;
@@ -14,7 +14,7 @@ export namespace RuleSceneApi {
createTime?: Date; createTime?: Date;
} }
/** IoT 场景联动规则触发器 */ /** 场景联动规则触发器 */
export interface Trigger { export interface Trigger {
type?: string; type?: string;
productId?: number; productId?: number;
@@ -26,13 +26,13 @@ export namespace RuleSceneApi {
conditionGroups?: TriggerConditionGroup[]; conditionGroups?: TriggerConditionGroup[];
} }
/** IoT 场景联动规则触发条件组 */ /** 场景联动规则触发条件组 */
export interface TriggerConditionGroup { export interface TriggerConditionGroup {
conditions?: TriggerCondition[]; conditions?: TriggerCondition[];
operator?: string; operator?: string;
} }
/** IoT 场景联动规则触发条件 */ /** 场景联动规则触发条件 */
export interface TriggerCondition { export interface TriggerCondition {
productId?: number; productId?: number;
deviceId?: number; deviceId?: number;
@@ -42,7 +42,7 @@ export namespace RuleSceneApi {
type?: string; type?: string;
} }
/** IoT 场景联动规则动作 */ /** 场景联动规则动作 */
export interface Action { export interface Action {
type?: string; type?: string;
productId?: number; productId?: number;
@@ -53,6 +53,7 @@ export namespace RuleSceneApi {
} }
} }
// TODO @haohao貌似下面的和 RuleSceneApi 重复了。
/** IoT 场景联动规则 */ /** IoT 场景联动规则 */
export interface IotSceneRule { export interface IotSceneRule {
id?: number; id?: number;
@@ -135,6 +136,7 @@ export function deleteSceneRule(id: number) {
} }
/** 批量删除场景联动规则 */ /** 批量删除场景联动规则 */
// TODO @haohao貌似用上。
export function deleteSceneRuleList(ids: number[]) { export function deleteSceneRuleList(ids: number[]) {
return requestClient.delete('/iot/scene-rule/delete-list', { return requestClient.delete('/iot/scene-rule/delete-list', {
params: { ids: ids.join(',') }, params: { ids: ids.join(',') },

View File

@@ -67,12 +67,6 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
title: '规则名称', title: '规则名称',
minWidth: 150, minWidth: 150,
}, },
{
field: 'productId',
title: '所属产品',
minWidth: 150,
slots: { default: 'product' },
},
{ {
field: 'description', field: 'description',
title: '规则描述', title: '规则描述',
@@ -87,6 +81,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
props: { type: DICT_TYPE.COMMON_STATUS }, props: { type: DICT_TYPE.COMMON_STATUS },
}, },
}, },
// TODO @haohao这里是【数据源】【数据目的】
{ {
field: 'sinkCount', field: 'sinkCount',
title: '数据流转数', title: '数据流转数',

View File

@@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
// TODO @haohao应该先有【规则】【目的】两个 tab然后在进行管理操作类似apps/web-antd/src/views/ai/chat/manager
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
@@ -42,10 +43,8 @@ async function handleDelete(row: any) {
duration: 0, duration: 0,
}); });
try { try {
await deleteDataRule(row.id); await deleteDataRule(row.id!);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
handleRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();

View File

@@ -25,12 +25,11 @@ const formRules: any = reactive({
}); });
const formRef = ref(); // 表单 Ref const formRef = ref(); // 表单 Ref
// 获取上行消息方法列表
const upstreamMethods = computed(() => { const upstreamMethods = computed(() => {
return Object.values(IotDeviceMessageMethodEnum).filter( return Object.values(IotDeviceMessageMethodEnum).filter(
(item) => item.upstream, (item) => item.upstream,
); );
}); }); // 获取上行消息方法列表
/** 根据产品 ID 过滤设备 */ /** 根据产品 ID 过滤设备 */
function getFilteredDevices(productId: number) { function getFilteredDevices(productId: number) {
@@ -193,7 +192,7 @@ const columns = [
{ {
title: '操作', title: '操作',
width: 80, width: 80,
fixed: 'right' as const, fixed: 'right',
}, },
]; ];
@@ -202,6 +201,8 @@ defineExpose({ validate, getData, setData });
<template> <template>
<Form ref="formRef" :model="{ data: formData }"> <Form ref="formRef" :model="{ data: formData }">
<!-- TODO @haohao貌似有告警 -->
<!-- TODO @haohao是不是搞成 web-antd/src/views/erp/finance/receipt/modules/item-form.vue 的做法通过 Grid apps/web-antd/src/views/infra/demo/demo03/erp/modules/demo03-grade-list.vue目的后续 ele 通用性更好 -->
<Table <Table
:columns="columns" :columns="columns"
:data-source="formData" :data-source="formData"

View File

@@ -21,6 +21,7 @@ const emit = defineEmits(['success']);
const formData = ref<any>(); const formData = ref<any>();
const sourceConfigRef = ref(); const sourceConfigRef = ref();
// TODO @haohao应该放到 modules
const getTitle = computed(() => { const getTitle = computed(() => {
return formData.value?.id return formData.value?.id
? $t('ui.actionTitle.edit', ['数据规则']) ? $t('ui.actionTitle.edit', ['数据规则'])
@@ -40,6 +41,7 @@ const [Form, formApi] = useVbenForm({
showDefaultActions: false, showDefaultActions: false,
}); });
// TODO @haohao这里需要优化下参考别的模块写法
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
async onConfirm() { async onConfirm() {
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();

View File

@@ -12,6 +12,8 @@ import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import DataRuleForm from './data-rule-form.vue'; import DataRuleForm from './data-rule-form.vue';
// TODO @haohao貌似和 apps/web-antd/src/views/iot/rule/data/index.vue 重复的。可能这个是对的。然后把 apps/web-antd/src/views/iot/rule/data/index.vue 搞成 tabs
/** IoT 数据流转规则列表 */ /** IoT 数据流转规则列表 */
defineOptions({ name: 'IotDataRule' }); defineOptions({ name: 'IotDataRule' });
@@ -43,9 +45,7 @@ async function handleDelete(row: any) {
}); });
try { try {
await deleteDataRule(row.id); await deleteDataRule(row.id);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
handleRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();

View File

@@ -120,6 +120,7 @@ watch(
<Form class="mx-4" /> <Form class="mx-4" />
<div v-if="formData" class="mx-4 mt-4"> <div v-if="formData" class="mx-4 mt-4">
<div class="mb-2 text-sm font-medium">配置信息</div> <div class="mb-2 text-sm font-medium">配置信息</div>
<!-- TODO @haohao下面的 form看看有没办法搞成 form schema 方便后续 ele 的迁移 -->
<HttpConfigForm <HttpConfigForm
v-if="IotDataSinkTypeEnum.HTTP === formData.type" v-if="IotDataSinkTypeEnum.HTTP === formData.type"
v-model="formData.config" v-model="formData.config"

View File

@@ -12,6 +12,8 @@ import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data'; import { useGridColumns, useGridFormSchema } from './data';
import DataSinkForm from './data-sink-form.vue'; import DataSinkForm from './data-sink-form.vue';
// TODO @haohao需要根据代码规范在优化下这个模块。和别的模块的风格保持一致。
/** IoT 数据流转目的列表 */ /** IoT 数据流转目的列表 */
defineOptions({ name: 'IotDataSink' }); defineOptions({ name: 'IotDataSink' });
@@ -43,9 +45,7 @@ async function handleDelete(row: any) {
}); });
try { try {
await deleteDataSink(row.id); await deleteDataSink(row.id);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
});
handleRefresh(); handleRefresh();
} finally { } finally {
hideLoading(); hideLoading();

View File

@@ -1,44 +0,0 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import { Button } from 'ant-design-vue';
defineOptions({ name: 'IotRuleDataBridge' });
</script>
<template>
<Page description="物聯網規則引擎 - 數據橋接" title="數據橋接">
<div class="p-4">
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/tree/master/src/views/iot/rule"
>
該功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/iot/rule/data/rule/index.vue"
>
可參考源代碼進行遷移
</Button>
<div class="mt-4">
<h3>功能說明</h3>
<p>規則引擎包括</p>
<ul>
<li>數據規則配置</li>
<li>數據轉發配置</li>
<li>場景聯動配置</li>
</ul>
<h3 class="mt-4">待實現</h3>
<ul>
<li> API 接口定義</li>
<li> 頁面實現</li>
</ul>
</div>
</div>
</Page>
</template>