Skip to content

Commit c46dfa0

Browse files
Kerrykerry-emqx
authored andcommitted
feat(RuleEngine):add IoT for RuleEngine; update logic in Bridge and Connector
1 parent 145a770 commit c46dfa0

File tree

16 files changed

+1765
-114
lines changed

16 files changed

+1765
-114
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "vue-cli-service lint"
1010
},
1111
"dependencies": {
12+
"@antv/g6": "^4.5.1",
1213
"@element-plus/icons": "^0.0.11",
1314
"@types/lodash": "^4.14.177",
1415
"axios": "^0.21.4",

src/api/ruleengine.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import http from "@/common/http";
2+
import { BridgeItem, RuleItem } from "@/types/ruleengine";
23

4+
//Bridges
35
export function getBridgeList(): Promise<any> {
46
return http.get("/bridges");
57
}
@@ -29,6 +31,12 @@ export function getBridgeInfo(id: string): Promise<any> {
2931
return http.get("/bridges/" + encodeURIComponent(id));
3032
}
3133

34+
export function deleteBridge(id: string): Promise<any> {
35+
if (!id) return Promise.reject();
36+
return http.delete("/bridges/" + encodeURIComponent(id));
37+
}
38+
39+
//Connectors
3240
export function getConnectorList(): Promise<any> {
3341
return http.get("/connectors");
3442
}
@@ -45,11 +53,35 @@ export function updateConnector(
4553
return http.put("/connectors/" + encodeURIComponent(id), body);
4654
}
4755

48-
export function deleteConnector(id: string) {
49-
if (!id) return;
56+
export function deleteConnector(id: string): Promise<any> {
57+
if (!id) return Promise.reject();
5058
return http.delete("/connectors/" + encodeURIComponent(id));
5159
}
5260

53-
export function getRules() {
61+
//Rules
62+
export function getRules(): Promise<any> {
5463
return http.get("/rules");
5564
}
65+
66+
export function getRuleInfo(id: string): Promise<any> {
67+
if (!id) return Promise.reject();
68+
return http.get("/rules/" + encodeURIComponent(id));
69+
}
70+
71+
export function createRules(body: Record<string, unknown>): Promise<any> {
72+
return http.post("/rules", body);
73+
}
74+
75+
export function getRuleEvents(): Promise<any> {
76+
return http.get("/rule_events");
77+
}
78+
79+
export function updateRules(id: string, body: RuleItem): Promise<any> {
80+
if (!id) return Promise.reject();
81+
return http.put("/rules/" + encodeURIComponent(id), body);
82+
}
83+
84+
export function deleteRules(id: string): Promise<any> {
85+
if (!id) return Promise.reject();
86+
return http.delete("/rules/" + encodeURIComponent(id));
87+
}

src/i18n/RuleEngine.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ export default {
179179
zh: "备注",
180180
en: "Note",
181181
},
182-
ruleid: {
183-
zh: "规则ID",
184-
en: "Rule ID",
182+
ruleName: {
183+
zh: "规则Name",
184+
en: "Rule Name",
185185
},
186186
filterData: {
187187
zh: "数据筛选",
@@ -211,4 +211,16 @@ export default {
211211
zh: "编辑输出",
212212
en: "Edit The Output",
213213
},
214+
testsql: {
215+
zh: "测试SQL",
216+
en: "Test SQL",
217+
},
218+
backToIoTList: {
219+
zh: "返回IoT规则列表",
220+
en: "Back To IoT Rules List",
221+
},
222+
backToBridggeList: {
223+
zh: "返回Bridge列表",
224+
en: "Back To Bridge List",
225+
},
214226
};

src/router/index.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import GatewayDetailListener from "@/views/Gateway/components/listeners.vue";
2626
import GatewayDetailAuth from "@/views/Gateway/components/auth.vue";
2727
import GatewayDetailClients from "@/views/Gateway/components/clients.vue";
2828
import GatewayCreate from "@/views/Gateway/GatewayCreate.vue";
29-
// import IoT from "@/views/RuleEngine/IoT/IoT.vue";
30-
// import IoTCreate from "@/views/RuleEngine/IoT/IoTCreate.vue";
29+
import IoT from "@/views/RuleEngine/IoT/IoT.vue";
30+
import IoTCreate from "@/views/RuleEngine/IoT/IoTCreate.vue";
31+
import IoTDetail from "@/views/RuleEngine/IoT/IoTDetail.vue";
3132
import Bridge from "@/views/RuleEngine/Bridge/DataBridge.vue";
3233
import BridgeCreate from "@/views/RuleEngine/Bridge/BridgeCreate.vue";
3334
import BridgeDetail from "@/views/RuleEngine/Bridge/BridgeDetail.vue";
@@ -302,27 +303,32 @@ export const routes: Array<RouteRecordRaw> = [
302303
},
303304
],
304305
},
305-
// //iot
306-
// {
307-
// path: "/iot",
308-
// component: Layout,
309-
// meta: {
310-
// hideKey: "iot",
311-
// authRequired: true,
312-
// },
313-
// children: [
314-
// {
315-
// path: "",
316-
// name: "iot",
317-
// component: IoT,
318-
// },
319-
// {
320-
// path: "create",
321-
// name: "iot-create",
322-
// component: IoTCreate,
323-
// },
324-
// ],
325-
// },
306+
//iot
307+
{
308+
path: "/iot",
309+
component: Layout,
310+
meta: {
311+
hideKey: "iot",
312+
authRequired: true,
313+
},
314+
children: [
315+
{
316+
path: "",
317+
name: "iot",
318+
component: IoT,
319+
},
320+
{
321+
path: "create",
322+
name: "iot-create",
323+
component: IoTCreate,
324+
},
325+
{
326+
path: "detail/:id",
327+
name: "iot-detail",
328+
component: IoTDetail,
329+
},
330+
],
331+
},
326332
//bridge
327333
{
328334
path: "/bridge",

src/types/ruleengine.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,20 @@ export interface ConnectorItem {
1919
export type BridgeItem = {
2020
id: string;
2121
status: string;
22+
direction: string;
23+
};
24+
25+
export type RuleItem = {
26+
outputs?: Array<Record<string, unknown> | string>;
27+
name?: string;
28+
enable?: boolean;
29+
sql?: string;
30+
description?: string;
31+
};
32+
33+
export type Rule = {
34+
enable: boolean;
35+
created_at: string;
36+
name: string;
37+
id: string;
2238
};

src/views/RuleEngine/Bridge/BridgeDetail.vue

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,60 @@
11
<template>
2-
<div class="bridge-detail" v-loading="infoLoading">
3-
<div class="section-header">
4-
<div>
5-
<img :src="bInfo.type && require(`@/assets/img/${bInfo.type}.png`)" />
6-
<span class="title-n-status">
7-
<span class="section-title">{{ id }}</span>
8-
<el-tag type="info" class="section-status">
9-
<span
10-
><i
11-
:class="['status', bInfo.status !== 'connected' && 'stopped']"
12-
></i
13-
><span>{{ bInfo.status }}</span></span
14-
>
15-
</el-tag>
16-
</span>
2+
<div class="bridge-detail">
3+
<router-link class="back-button" :to="{ name: 'data-bridge' }">{{
4+
tl("backToBridggeList")
5+
}}</router-link>
6+
<div class="detail-main" v-loading="infoLoading">
7+
<div class="section-header">
8+
<div>
9+
<img :src="bInfo.type && require(`@/assets/img/${bInfo.type}.png`)" />
10+
<span class="title-n-status">
11+
<span class="section-title">{{ id }}</span>
12+
<el-tag type="info" class="section-status">
13+
<span
14+
><i
15+
:class="['status', bInfo.status !== 'connected' && 'stopped']"
16+
></i
17+
><span>{{ bInfo.status }}</span></span
18+
>
19+
</el-tag>
20+
</span>
21+
</div>
22+
<div>
23+
<el-button type="danger" size="small">{{
24+
$t("Base.delete")
25+
}}</el-button>
26+
<el-button size="small" @click="enableOrDisableBridge">
27+
{{
28+
bInfo.status === "connected"
29+
? $t("Base.disable")
30+
: $t("Base.enable")
31+
}}</el-button
32+
>
33+
</div>
1734
</div>
18-
<div>
19-
<el-button type="danger" size="small">{{
20-
$t("Base.delete")
21-
}}</el-button>
22-
<el-button size="small" @click="enableOrDisableBridge">
23-
{{
24-
bInfo.status === "connected"
25-
? $t("Base.disable")
26-
: $t("Base.enable")
27-
}}</el-button
35+
<div class="setting-area">
36+
<bridge-http-config
37+
v-if="bInfo.type === 'http'"
38+
v-model:tls="bInfo.ssl"
39+
v-model="bInfo"
40+
:edit="true"
41+
></bridge-http-config>
42+
<bridge-mqtt-config
43+
v-if="bInfo.type === 'mqtt'"
44+
v-model="bInfo"
45+
></bridge-mqtt-config>
46+
</div>
47+
<div class="btn-area">
48+
<el-button
49+
type="primary"
50+
size="small"
51+
v-if="bInfo.type"
52+
:loading="infoLoading"
53+
@click="updateBridgeInfo()"
54+
>{{ $t("Base.update") }}</el-button
2855
>
2956
</div>
3057
</div>
31-
<div class="setting-area">
32-
<bridge-http-config
33-
v-if="bInfo.type === 'http'"
34-
v-model:tls="bInfo.ssl"
35-
v-model="bInfo"
36-
:edit="true"
37-
></bridge-http-config>
38-
<bridge-mqtt-config
39-
v-if="bInfo.type === 'mqtt'"
40-
v-model="bInfo"
41-
></bridge-mqtt-config>
42-
</div>
43-
<div class="btn-area">
44-
<el-button
45-
type="primary"
46-
size="small"
47-
v-if="bInfo.type"
48-
:loading="infoLoading"
49-
@click="updateBridgeInfo()"
50-
>{{ $t("Base.update") }}</el-button
51-
>
52-
</div>
5358
</div>
5459
</template>
5560

@@ -91,12 +96,12 @@ export default defineComponent({
9196
infoLoading.value = false;
9297
};
9398
94-
watch(
95-
() => [_.cloneDeep(bInfo.value)],
96-
(val) => {
97-
console.log(val);
98-
}
99-
);
99+
// watch(
100+
// () => [_.cloneDeep(bInfo.value)],
101+
// (val) => {
102+
// console.log(val);
103+
// }
104+
// );
100105
101106
const enableOrDisableBridge = async () => {
102107
// tbLoading.value = true;

src/views/RuleEngine/Bridge/BridgeMqttConfig.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@
100100
></el-checkbox>
101101
</el-col>
102102
<el-col :span="24">
103-
<el-form-item label="Payload"> </el-form-item>
103+
<el-form-item label="Payload">
104+
<el-input
105+
type="textarea"
106+
rows="10"
107+
v-model="mqttBridgeVal.payload"
108+
></el-input>
109+
</el-form-item>
104110
</el-col>
105111
</el-row>
106112
</template>

src/views/RuleEngine/Bridge/DataBridge.vue

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@
6262
? $t("Base.disable")
6363
: $t("Base.enable")
6464
}}</el-button>
65-
<el-button size="mini" type="danger">{{
66-
$t("Base.delete")
67-
}}</el-button>
65+
<el-button
66+
size="mini"
67+
type="danger"
68+
@click="submitDeleteBridge(row.id)"
69+
>{{ $t("Base.delete") }}</el-button
70+
>
6871
</template>
6972
</el-table-column>
7073
</el-table>
@@ -75,7 +78,12 @@
7578

7679
<script lang="ts">
7780
import { defineComponent, onMounted, ref } from "vue";
78-
import { getBridgeList, updateBridge, startStopBridge } from "@/api/ruleengine";
81+
import {
82+
getBridgeList,
83+
updateBridge,
84+
startStopBridge,
85+
deleteBridge,
86+
} from "@/api/ruleengine";
7987
import { useI18n } from "vue-i18n";
8088
import { BridgeItem } from "@/types/ruleengine";
8189
import _ from "lodash";
@@ -120,13 +128,36 @@ export default defineComponent({
120128
tbLoading.value = false;
121129
};
122130
131+
const submitDeleteBridge = async (id: string) => {
132+
MB.confirm(t("General.confirmDelete"), {
133+
confirmButtonText: t("Base.confirm"),
134+
cancelButtonText: t("Base.cancel"),
135+
type: "warning",
136+
})
137+
.then(async () => {
138+
tbLoading.value = true;
139+
140+
const res = await deleteBridge(id).catch(() => {});
141+
if (res) {
142+
M({
143+
type: "success",
144+
message: t("Base.deleteSuccess"),
145+
});
146+
listBridge();
147+
tbLoading.value = false;
148+
}
149+
})
150+
.catch(() => {});
151+
};
152+
123153
onMounted(listBridge);
124154
125155
return {
126156
tl: (key: string) => t("RuleEngine." + key),
127157
bridgeTb,
128158
tbLoading,
129159
enableOrDisableBridge,
160+
submitDeleteBridge,
130161
};
131162
},
132163
});

0 commit comments

Comments
 (0)