Browse Source

jiahan.wu cr: tb设备同步

develop
eric777 8 months ago
parent
commit
66f540347b
  1. 8
      src/api/model/device.js
  2. 72
      src/views/model/device/index.vue

8
src/api/model/device.js

@ -108,4 +108,12 @@ export function addAndSyncParamMap(data) {
method: 'post',
data: data
});
}
// 同步TB设备信息
export function syncTbDevice(id) {
return request({
url: '/model/dcBaseDeviceinfo/syncTbDevice/' + id,
method: 'post'
})
}

72
src/views/model/device/index.vue

@ -49,7 +49,7 @@
<el-col :span="4" v-show="collapseVisible">
<el-form-item label="设备类型" prop="deviceType" label-width="auto">
<el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" clearable>
<el-option v-for="dict in dc_device_type" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in dc_device_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
</el-form-item>
</el-col>
@ -217,6 +217,7 @@
</template>
<template #default="scope">
<el-button type="text" icon="Edit" @click="handleParams(scope.row)">维护设备参数</el-button>
<el-button type="text" icon="Download" v-if="scope.row.deviceType == '0' && scope.row.deviceSourceId == '001'" @click="handleSyncTbDevice(scope.row)">同步TB设备信息</el-button>
<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
<el-button type="text" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
</template>
@ -268,13 +269,13 @@
</el-form-item>
</el-col>
<el-col :span="12" v-show="thingsboardShow">
<el-form-item label="thingsboard服务" prop="thingsboardServer">
<el-select v-model="form.thingsboardServer" placeholder="请选择thingsboard服务">
<el-form-item label="thingsboard服务" prop="serverinfoId">
<el-select v-model="form.serverinfoId" placeholder="请选择thingsboard服务">
<el-option v-for="dict in tbServerList" :key="dict.id" :label="dict.seviceName" :value="dict.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12" v-show="thingsboardShow">
<el-col :span="12" v-show=false>
<el-form-item label="是否同步设备到tb服务" prop="synchroDevice">
<el-select v-model="form.synchroDevice" placeholder="请选择是否同步设备到tb服务">
<el-option v-for="dict in synchro_device" :key="dict.value" :label="dict.label" :value="dict.value" />
@ -290,7 +291,7 @@
</el-col>
<el-col :span="12">
<el-form-item label="设备类型" prop="deviceType">
<el-select v-model="form.deviceType" placeholder="请选择设备类型">
<el-select v-model="form.deviceType" placeholder="请选择设备类型" @change="deviceTypeChange">
<el-option v-for="dict in dc_device_type" :key="dict.value" :label="dict.label" :value="dict.value">
</el-option>
</el-select>
@ -438,7 +439,7 @@
}
</style>
<script setup name="Device">
import { getUuid, getDevice, delDevice, addDevice, updateDevice, listWithFilterColumn, selectDcBaseDeviceinfoMaxSort, cleanRedisCache, addAndSyncParamMap } from "@/api/model/device";
import { getUuid, getDevice, delDevice, addDevice, updateDevice, listWithFilterColumn, selectDcBaseDeviceinfoMaxSort, cleanRedisCache, addAndSyncParamMap, syncTbDevice } from "@/api/model/device";
import { listDevicemodel, } from "@/api/model/devicemodel";
import { deptTreeSelect } from "@/api/system/user";
import { listserverinfoNoPage, } from "@/api/model/tbserverinfo";
@ -547,12 +548,12 @@ const data = reactive({
orgName: [
{ required: true, message: "所属组织名称", trigger: "change" }
],
thingsboardServer: [
serverinfoId: [
{ required: thingsboardShow, message: "thingsboard服务", trigger: "change" }
],
synchroDevice: [
{ required: thingsboardShow, message: "是否同步设备到tb服务", trigger: "change" }
],
// synchroDevice: [
// { required: thingsboardShow, message: "tb", trigger: "change" }
// ],
}
});
@ -616,8 +617,10 @@ function reset() {
deleteBy: null,
deleteTime: null,
id: null,
serverinfoId: null,
deviceGroupName: null
};
thingsboardShow.value = false;
proxy.resetForm("deviceRef");
}
@ -648,7 +651,7 @@ function handleSelectionChange(selection) {
/** 新增按钮操作 */
function handleAdd() {
reset();
loading.value = true;
// loading.value = true;
// getUuid().then(response => {
// form.value.centerDeviceCode = response.msg;
// form.value.uuid = response.msg;
@ -658,9 +661,10 @@ function handleAdd() {
form.value.sort = response.data?.sort + 1;
loading.value = false;
})
disabledDeviceCode.value = true;
// disabledDeviceCode.value = true;
open.value = true;
title.value = "添加设备信息";
getThServerList();
}
/** 修改按钮操作 */
@ -681,7 +685,11 @@ function handleUpdate(row) {
return;
}
getDevice(_id).then(response => {
getThServerList();
form.value = response.data;
if(form.value.deviceType == '0' && form.value.deviceSourceId == '001'){
thingsboardShow.value = true;
}
open.value = true;
disabledDeviceCode.value = true;
title.value = "修改设备信息";
@ -815,6 +823,18 @@ function handleParams(row) {
});
}
function handleSyncTbDevice(row) {
proxy.$modal.confirm('是否确认同步"' + row.deviceName + '"的ThingsBoard设备信息?').then(function () {
syncTbDevice(row.id).then(response => {
if (response.code == 200) {
proxy.$modal.msgSuccess("同步成功");
} else {
proxy.$modal.msgSuccess(response.message);
}
});
})
}
function toggleCollapse() {
collapseVisible.value = !collapseVisible.value;
if (collapseVisible.value) {
@ -839,17 +859,29 @@ function deviceSourceChange(val) {
if (item.value == val) {
form.value.deviceSource = item.label;
}
// if (val == '002') {
// ioserverShow.value = true;
// thingsboardShow.value = false;
// } else if (val == '001') {
// getThServerList();
// ioserverShow.value = false;
// thingsboardShow.value = true;
// }
if (form.value.deviceSourceId == '001' && form.value.deviceType == '0') {
// ioserverShow.value = false;
thingsboardShow.value = true;
} else {
// ioserverShow.value = true;
thingsboardShow.value = false;
// form.value.serverinfoId = null;
}
})
}
function deviceTypeChange(){
if (form.value.deviceSourceId == '001' && form.value.deviceType == '0') {
getThServerList();
// ioserverShow.value = false;
thingsboardShow.value = true;
} else {
// ioserverShow.value = true;
thingsboardShow.value = false;
// form.value.serverinfoId = null;
}
}
function toggleFixedColumns() {
fixedColumns.value = !fixedColumns.value;
}

Loading…
Cancel
Save