feat(智能柜): 新增MQTT网关配置功能
在智能柜模块中新增MQTT网关配置功能,包括MQTT服务管理界面、网关配置弹窗及相关接口。智能柜接口新增mqttServerId字段,支持配置网关服务。此功能允许用户为智能柜配置MQTT网关,以实现设备通信。
This commit is contained in:
parent
f39d1f48e4
commit
c2a1dc915c
|
@ -0,0 +1,52 @@
|
|||
import { http } from '@/utils/http';
|
||||
|
||||
export interface SearchMqttServerQuery extends BasePageQuery {
|
||||
serverUrl?: string;
|
||||
username?: string;
|
||||
}
|
||||
|
||||
export interface MqttServerDTO {
|
||||
mqttServerId?: number;
|
||||
serverUrl: string;
|
||||
username: string;
|
||||
password: string;
|
||||
topicFilter: string;
|
||||
publishTopic: string;
|
||||
}
|
||||
|
||||
export interface AddMqttServerCommand {
|
||||
serverUrl: string;
|
||||
username: string;
|
||||
password: string;
|
||||
topicFilter: string;
|
||||
publishTopic: string;
|
||||
}
|
||||
|
||||
export interface UpdateMqttServerCommand extends AddMqttServerCommand {
|
||||
mqttServerId: number;
|
||||
}
|
||||
|
||||
export const getMqttServerList = (params?: SearchMqttServerQuery) => {
|
||||
return http.request<ResponseData<PageDTO<MqttServerDTO>>>('get', '/cabinet/mqttServer', {
|
||||
params
|
||||
});
|
||||
};
|
||||
|
||||
export const addMqttServer = (data: AddMqttServerCommand) => {
|
||||
return http.request<ResponseData<void>>('post', '/cabinet/mqttServer', {
|
||||
data
|
||||
});
|
||||
};
|
||||
|
||||
export const updateMqttServer = (serverId: number, data: UpdateMqttServerCommand) => {
|
||||
return http.request<ResponseData<void>>('put', `/cabinet/mqttServer/${serverId}`, {
|
||||
data: {
|
||||
...data,
|
||||
mqttServerId: serverId
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteMqttServer = (ids: string) => {
|
||||
return http.request<ResponseData<void>>('delete', `/cabinet/mqttServer/${ids}`);
|
||||
};
|
|
@ -11,6 +11,7 @@ export interface SmartCabinetDTO {
|
|||
cabinetId?: number;
|
||||
cabinetName: string;
|
||||
cabinetType: number;
|
||||
mqttServerId?: number;
|
||||
templateNo: string;
|
||||
lockControlNo: number;
|
||||
location: number;
|
||||
|
@ -20,12 +21,20 @@ export interface SmartCabinetDTO {
|
|||
export interface AddSmartCabinetCommand {
|
||||
cabinetName: string;
|
||||
cabinetType: number;
|
||||
mqttServerId?: number;
|
||||
templateNo: string;
|
||||
lockControlNo: number;
|
||||
location: number;
|
||||
}
|
||||
|
||||
export interface UpdateSmartCabinetCommand extends AddSmartCabinetCommand {
|
||||
export interface UpdateSmartCabinetCommand {
|
||||
cabinetId: number;
|
||||
cabinetName?: string;
|
||||
cabinetType?: number;
|
||||
mqttServerId?: number;
|
||||
templateNo?: string;
|
||||
lockControlNo?: number;
|
||||
location?: number;
|
||||
}
|
||||
|
||||
export interface AllCabinetDataDTO {
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { PureTableBar } from "@/components/RePureTableBar";
|
||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||
import { getMqttServerList, MqttServerDTO, deleteMqttServer, SearchMqttServerQuery } from "@/api/cabinet/mqttServer";
|
||||
import EditPen from "@iconify-icons/ep/edit-pen";
|
||||
import Delete from "@iconify-icons/ep/delete";
|
||||
import AddFill from "@iconify-icons/ri/add-circle-line";
|
||||
import Search from "@iconify-icons/ep/search";
|
||||
import Refresh from "@iconify-icons/ep/refresh";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import MqttServerFormModal from "./mqtt-server-form-modal.vue";
|
||||
|
||||
defineOptions({
|
||||
name: "MqttServer"
|
||||
});
|
||||
|
||||
const formRef = ref();
|
||||
const tableRef = ref();
|
||||
const modalVisible = ref(false);
|
||||
const handleRefresh = () => {
|
||||
getList();
|
||||
modalVisible.value = false;
|
||||
editVisible.value = false;
|
||||
};
|
||||
|
||||
const searchFormParams = ref<SearchMqttServerQuery>({
|
||||
serverUrl: "",
|
||||
username: ""
|
||||
});
|
||||
|
||||
const pagination = ref({
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const dataList = ref<MqttServerDTO[]>([]);
|
||||
const multipleSelection = ref<number[]>([]);
|
||||
const editVisible = ref(false);
|
||||
const currentRow = ref<MqttServerDTO>();
|
||||
|
||||
const getList = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const { data } = await getMqttServerList({
|
||||
...searchFormParams.value,
|
||||
pageSize: pagination.value.pageSize,
|
||||
pageNum: pagination.value.currentPage
|
||||
});
|
||||
dataList.value = data.rows;
|
||||
pagination.value.total = data.total;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSearch = () => {
|
||||
pagination.value.currentPage = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
formRef.value.resetFields();
|
||||
onSearch();
|
||||
};
|
||||
|
||||
const onSizeChange = (val: number) => {
|
||||
pagination.value.pageSize = val;
|
||||
getList();
|
||||
};
|
||||
|
||||
const onCurrentChange = (val: number) => {
|
||||
pagination.value.currentPage = val;
|
||||
getList();
|
||||
};
|
||||
|
||||
const handleDelete = async (row: MqttServerDTO) => {
|
||||
try {
|
||||
await deleteMqttServer(row.mqttServerId!.toString());
|
||||
ElMessage.success("删除成功");
|
||||
getList();
|
||||
} catch (error) {
|
||||
console.error("删除失败", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBulkDelete = async () => {
|
||||
if (multipleSelection.value.length === 0) return;
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认删除选中的${multipleSelection.value.length}项MQTT服务吗?`,
|
||||
"警告",
|
||||
{ confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
|
||||
);
|
||||
|
||||
await deleteMqttServer(multipleSelection.value.join(","));
|
||||
ElMessage.success("批量删除成功");
|
||||
multipleSelection.value = [];
|
||||
getList();
|
||||
} catch (error) {
|
||||
console.error("删除取消或失败", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectionChange = (rows: MqttServerDTO[]) => {
|
||||
multipleSelection.value = rows.map(row => row.mqttServerId!);
|
||||
};
|
||||
|
||||
const handleEdit = (row: MqttServerDTO) => {
|
||||
currentRow.value = row;
|
||||
editVisible.value = true;
|
||||
};
|
||||
|
||||
getList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="main">
|
||||
<el-form ref="formRef" :inline="true" :model="searchFormParams"
|
||||
class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]">
|
||||
<el-form-item label="服务地址:" prop="serverUrl">
|
||||
<el-input v-model="searchFormParams.serverUrl" placeholder="请输入服务地址" clearable class="!w-[200px]" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名:" prop="username">
|
||||
<el-input v-model="searchFormParams.username" placeholder="请输入用户名" clearable class="!w-[200px]" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :icon="useRenderIcon(Search)" @click="onSearch">
|
||||
搜索
|
||||
</el-button>
|
||||
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm">
|
||||
重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<PureTableBar title="MQTT服务管理" @refresh="getList">
|
||||
<template #buttons>
|
||||
<el-button type="primary" :icon="useRenderIcon(AddFill)" @click="modalVisible = true">
|
||||
新增服务
|
||||
</el-button>
|
||||
<el-button type="danger" :icon="useRenderIcon(Delete)" :disabled="multipleSelection.length === 0"
|
||||
@click="handleBulkDelete">
|
||||
批量删除
|
||||
</el-button>
|
||||
</template>
|
||||
<el-table ref="tableRef" v-loading="loading" :data="dataList" row-key="id"
|
||||
@selection-change="handleSelectionChange" border>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column label="服务ID" prop="mqttServerId" width="100" />
|
||||
<el-table-column label="服务地址" prop="serverUrl" />
|
||||
<el-table-column label="用户名" prop="username" width="120" />
|
||||
<el-table-column label="主题过滤" prop="topicFilter" width="180" />
|
||||
<el-table-column label="发布主题" prop="publishTopic" width="120" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link :icon="useRenderIcon(EditPen)" @click="handleEdit(row)">
|
||||
编辑
|
||||
</el-button>
|
||||
<el-popconfirm :title="`确认删除【${row.serverUrl}】?`" @confirm="handleDelete(row)">
|
||||
<template #reference>
|
||||
<el-button type="danger" link :icon="useRenderIcon(Delete)">
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
|
||||
@size-change="onSizeChange" @current-change="onCurrentChange" />
|
||||
</PureTableBar>
|
||||
<MqttServerFormModal :visible="modalVisible" @update:visible="val => modalVisible = val" @refresh="handleRefresh" />
|
||||
<MqttServerFormModal :visible="editVisible" :row="currentRow" @update:visible="val => editVisible = val"
|
||||
@refresh="handleRefresh" />
|
||||
</div>
|
||||
</template>
|
|
@ -0,0 +1,112 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { addMqttServer, updateMqttServer, MqttServerDTO, UpdateMqttServerCommand } from "@/api/cabinet/mqttServer";
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
row: {
|
||||
type: Object as () => MqttServerDTO,
|
||||
default: () => ({})
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(["update:visible", "refresh"]);
|
||||
|
||||
const formRef = ref();
|
||||
const formData = ref<UpdateMqttServerCommand>({
|
||||
mqttServerId: 0,
|
||||
serverUrl: "",
|
||||
username: "",
|
||||
password: "",
|
||||
topicFilter: "",
|
||||
publishTopic: ""
|
||||
});
|
||||
|
||||
const rules = {
|
||||
serverUrl: [{ required: true, message: "请输入服务地址", trigger: "blur" }],
|
||||
username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
|
||||
password: [{ required: true, message: "请输入密码", trigger: "blur" }],
|
||||
topicFilter: [{ required: true, message: "请输入主题过滤", trigger: "blur" }],
|
||||
publishTopic: [{ required: true, message: "请输入发布主题", trigger: "blur" }]
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
val => {
|
||||
if (val) {
|
||||
if (props.row?.mqttServerId) {
|
||||
formData.value = {
|
||||
...props.row,
|
||||
mqttServerId: props.row.mqttServerId
|
||||
};
|
||||
} else {
|
||||
formData.value = {
|
||||
mqttServerId: 0,
|
||||
serverUrl: "",
|
||||
username: "",
|
||||
password: "",
|
||||
topicFilter: "",
|
||||
publishTopic: ""
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await formRef.value.validate();
|
||||
|
||||
if (formData.value.mqttServerId) {
|
||||
await updateMqttServer(formData.value.mqttServerId, formData.value);
|
||||
ElMessage.success("修改成功");
|
||||
} else {
|
||||
await addMqttServer(formData.value);
|
||||
ElMessage.success("新增成功");
|
||||
}
|
||||
|
||||
emit("update:visible", false);
|
||||
emit("refresh");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
emit("update:visible", false);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-dialog :title="formData.mqttServerId ? '编辑MQTT服务' : '新增MQTT服务'" :model-value="visible"
|
||||
@update:model-value="handleClose" width="600px">
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
|
||||
<el-form-item label="服务ID" prop="mqttServerId" v-if="formData.mqttServerId">
|
||||
<el-input v-model="formData.mqttServerId" :disabled="true" />
|
||||
</el-form-item>
|
||||
<el-form-item label="服务地址" prop="serverUrl">
|
||||
<el-input v-model="formData.serverUrl" placeholder="请输入服务地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="formData.username" placeholder="请输入用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input v-model="formData.password" type="password" placeholder="请输入密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="主题过滤" prop="topicFilter">
|
||||
<el-input v-model="formData.topicFilter" placeholder="请输入主题过滤" />
|
||||
</el-form-item>
|
||||
<el-form-item label="发布主题" prop="publishTopic">
|
||||
<el-input v-model="formData.publishTopic" placeholder="请输入发布主题" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
|
@ -0,0 +1,90 @@
|
|||
<template>
|
||||
<el-dialog v-model="visible" title="MQTT网关配置" width="800px">
|
||||
<el-table :data="mqttList" v-loading="loading" border>
|
||||
<el-table-column prop="mqttServerId" label="服务ID" width="100" />
|
||||
<el-table-column prop="serverUrl" label="服务地址" />
|
||||
<el-table-column prop="username" label="用户名" width="120" />
|
||||
<el-table-column label="操作" width="80" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="handleConfig(row)">配置</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
|
||||
@size-change="onSizeChange" @current-change="onCurrentChange" />
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { getMqttServerList } from '@/api/cabinet/mqttServer';
|
||||
import { MqttServerDTO } from '@/api/cabinet/mqttServer';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { updateSmartCabinet } from '@/api/cabinet/smart-cabinet';
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean;
|
||||
cabinetId: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
|
||||
const visible = ref(props.modelValue);
|
||||
const mqttList = ref<MqttServerDTO[]>([]);
|
||||
const loading = ref(false);
|
||||
const currentCabinetId = ref<number>();
|
||||
const pagination = ref({
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
total: 0
|
||||
});
|
||||
|
||||
const loadMqttServers = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const { data } = await getMqttServerList({
|
||||
pageSize: pagination.value.pageSize,
|
||||
pageNum: pagination.value.currentPage
|
||||
});
|
||||
mqttList.value = data.rows;
|
||||
pagination.value.total = data.total;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onSizeChange = (val: number) => {
|
||||
pagination.value.pageSize = val;
|
||||
loadMqttServers();
|
||||
};
|
||||
|
||||
const onCurrentChange = (val: number) => {
|
||||
pagination.value.currentPage = val;
|
||||
loadMqttServers();
|
||||
};
|
||||
|
||||
watch(() => props.modelValue, (val) => {
|
||||
visible.value = val;
|
||||
});
|
||||
|
||||
watch(() => props.cabinetId, (newVal) => {
|
||||
if (newVal) {
|
||||
currentCabinetId.value = newVal;
|
||||
loadMqttServers();
|
||||
}
|
||||
});
|
||||
|
||||
const handleConfig = async (row: MqttServerDTO) => {
|
||||
try {
|
||||
await updateSmartCabinet(currentCabinetId.value, {
|
||||
cabinetId: currentCabinetId.value,
|
||||
mqttServerId: row.mqttServerId
|
||||
});
|
||||
ElMessage.success('配置成功');
|
||||
emit('update:modelValue', false);
|
||||
} catch (error) {
|
||||
console.error('配置失败', error);
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -14,6 +14,7 @@ import { ElMessage, ElMessageBox } from "element-plus";
|
|||
import router from "@/router";
|
||||
import { deleteSmartCabinet } from "@/api/cabinet/smart-cabinet";
|
||||
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
|
||||
import GatewayConfigModal from "./GatewayConfigModal.vue";
|
||||
|
||||
defineOptions({
|
||||
name: "SmartCabinet"
|
||||
|
@ -39,6 +40,8 @@ const dataList = ref([]);
|
|||
const multipleSelection = ref<number[]>([]);
|
||||
const editVisible = ref(false);
|
||||
const currentRow = ref<SmartCabinetDTO>();
|
||||
const gatewayConfigVisible = ref(false);
|
||||
const currentCabinetId = ref<number>();
|
||||
|
||||
const getList = async () => {
|
||||
try {
|
||||
|
@ -130,6 +133,11 @@ const handleEdit = (row: SmartCabinetDTO) => {
|
|||
editVisible.value = true;
|
||||
};
|
||||
|
||||
const handleGatewayConfig = (row: SmartCabinetDTO) => {
|
||||
currentCabinetId.value = row.cabinetId;
|
||||
gatewayConfigVisible.value = true;
|
||||
};
|
||||
|
||||
getList();
|
||||
</script>
|
||||
|
||||
|
@ -177,6 +185,7 @@ getList();
|
|||
</el-table-column>
|
||||
<el-table-column label="模板编号" prop="templateNo" width="180" />
|
||||
<el-table-column label="锁控编号" prop="lockControlNo" width="120" />
|
||||
<el-table-column label="网关ID" prop="mqttServerId" width="120" />
|
||||
<el-table-column label="位置" prop="location" width="120" />
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
|
@ -187,6 +196,10 @@ getList();
|
|||
@click="goCellManagement(row)">
|
||||
格口
|
||||
</el-button>
|
||||
<el-button type="warning" link :icon="useRenderIcon('ant-design:gateway-outlined')"
|
||||
@click="handleGatewayConfig(row)">
|
||||
配置网关
|
||||
</el-button>
|
||||
<el-popconfirm :title="`确认删除【${row.cabinetName}】?`" @confirm="handleDelete(row)">
|
||||
<template #reference>
|
||||
<el-button type="danger" link :icon="useRenderIcon(Delete)">
|
||||
|
@ -203,5 +216,6 @@ getList();
|
|||
</PureTableBar>
|
||||
<smart-cabinet-form-modal v-model:visible="modalVisible" @refresh="getList" />
|
||||
<smart-cabinet-edit-modal v-model:visible="editVisible" :row="currentRow" @refresh="getList" />
|
||||
<GatewayConfigModal v-model="gatewayConfigVisible" :cabinet-id="currentCabinetId" />
|
||||
</div>
|
||||
</template>
|
Loading…
Reference in New Issue