发布v1.1版本

This commit is contained in:
kerwincui
2022-03-16 14:10:16 +08:00
parent 808b7a20bf
commit 8b9b34ce41
835 changed files with 99635 additions and 0 deletions

View File

@@ -0,0 +1,406 @@
<template>
<el-card style="margin:6px;padding-bottom:100px;">
<el-tabs v-model="activeName" tab-position="left" style="padding:10px;">
<el-tab-pane name="basic">
<span slot="label"> * 基本信息</span>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-row :gutter="100">
<el-col :span="7">
<el-form-item label="设备名称" prop="deviceName">
<el-input v-model="form.deviceName" placeholder="请输入设备名称" />
</el-form-item>
<el-form-item label="" prop="serialNumber">
<template slot="label">
<span style="color:red;">* </span>设备编号
</template>
<el-input v-model="form.serialNumber" placeholder="请输入设备编号" :disabled="form.status!=1">
<el-button slot="append" @click="generateNum" :loading="genDisabled" :disabled="form.status!=1">生成</el-button>
</el-input>
</el-form-item>
<el-form-item label="" prop="productName">
<template slot="label">
<span style="color:red;">* </span>所属产品
</template>
<el-input readonly v-model="form.productName" placeholder="请选择产品" :disabled="form.status!=1">
<el-button slot="append" @click="selectProduct()" :disabled="form.status!=1">选择</el-button>
</el-input>
</el-form-item>
<el-form-item label="固件版本" prop="firmwareVersion">
<el-input v-model="form.firmwareVersion" placeholder="请输入固件版本" type="number" :disabled="form.status!=1">
<template slot="prepend">Version</template>
</el-input>
</el-form-item>
<el-form-item label="禁用设备" prop="deviceStatus">
<el-switch v-model="deviceStatus" active-text="" inactive-text="" :disabled="form.status==1" :active-value="1" :inactive-value="0" active-color="#F56C6C">
</el-switch>
</el-form-item>
<el-form-item label="设备影子" prop="isShadow">
<el-switch v-model="form.isShadow" active-text="" inactive-text="" :active-value="1" :inactive-value="0">
</el-switch>
</el-form-item>
<el-form-item label="备注信息" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" rows="4" />
</el-form-item>
</el-col>
<el-col :span="7">
<!--
<el-form-item label="设备图片" prop="imageUrl">
<el-image style="height:225px;border:1px solid #dee4ed;border-radius:5px;padding:5px;" :src="imageUrl" :preview-src-list="[imageUrl]" fit="cover"></el-image>
</el-form-item>
-->
<el-form-item label="自定义位置" prop="isCustomLocation">
<el-switch v-model="form.isCustomLocation" active-text="" inactive-text="" :active-value="1" :inactive-value="0">
</el-switch>
</el-form-item>
<el-form-item label="设备经度" prop="longitude">
<el-input v-model="form.longitude" placeholder="请输入设备经度" type="number" :disabled="form.isCustomLocation==0">
<el-link slot="append" :underline="false" href="https://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">坐标拾取</el-link>
</el-input>
</el-form-item>
<el-form-item label="设备纬度" prop="latitude">
<el-input v-model="form.latitude" placeholder="请输入设备纬度" type="number" :disabled="form.isCustomLocation==0">
<el-link slot="append" :underline="false" href="https://api.map.baidu.com/lbsapi/getpoint/index.html" target="_blank">坐标拾取</el-link>
</el-input>
</el-form-item>
<el-form-item label="所在地址" prop="networkAddress">
<el-input v-model="form.networkAddress" placeholder="请输入设备所在地址" :disabled="form.isCustomLocation==0" />
</el-form-item>
<el-form-item label="入网地址" prop="networkIp">
<el-input v-model="form.networkIp" placeholder="设备入网IP" disabled />
</el-form-item>
<el-form-item label="激活时间" prop="activeTime">
<el-date-picker clearable v-model="form.activeTime" type="date" value-format="yyyy-MM-dd" placeholder="设备激活时间" disabled style="width:100%">
</el-date-picker>
</el-form-item>
<el-form-item label="设备信号" prop="rssi">
<el-input v-model="form.rssi" placeholder="设备信号强度" disabled />
</el-form-item>
<el-form-item label="设备状态" prop="status">
<dict-tag :options="dict.type.iot_device_status" :value="form.status" style="width:60px;display:inline-block;" />
</el-form-item>
</el-col>
<el-col :span="10">
<div style="border:1px solid #dfe4ed;border-radius:5px;padding:5px;text-align:center;line-height:400px;">
<div id="map" style="height:435px;width:100%;">地图展示区域新增后显示</div>
</div>
</el-col>
</el-row>
</el-form>
<el-form label-width="100px" style="margin-top:50px;">
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
<el-button size="small" type="primary" @click="submitForm"> </el-button>
</el-form-item>
</el-form>
<!-- 选择产品 -->
<product-list ref="productList" :productId="form.productId" @productEvent="getProductData($event)" />
</el-tab-pane>
<el-tab-pane name="runningStatus" :disabled="form.deviceId==0">
<span slot="label">运行状态</span>
<running-status ref="runningStatus" :device="form" />
</el-tab-pane>
<el-tab-pane name="deviceTimer" :disabled="form.deviceId==0">
<span slot="label">设备定时</span>
<device-timer ref="deviceTimer" :device="form" />
</el-tab-pane>
<!--
<el-tab-pane name="deviceUser" :disabled="form.deviceId==0">
<span slot="label">设备用户</span>
<device-user ref="deviceUser" :device="form" @userEvent="getUserData($event)" />
</el-tab-pane>
-->
<el-tab-pane name="deviceLog" :disabled="form.deviceId==0">
<span slot="label">设备日志</span>
<device-log ref="deviceLog" :device="form" />
</el-tab-pane>
<el-tab-pane name="deviceStastic" :disabled="form.deviceId==0">
<span slot="label">监测统计</span>
<device-statistic ref="deviceStatistic" :device="form" />
</el-tab-pane>
<el-tab-pane label="" disabled name="device01" />
<el-tab-pane label="" disabled name="device02" />
<el-tab-pane label="" disabled name="device03" />
<el-tab-pane name="device04">
<span slot="label">
<el-tooltip class="item" effect="dark" content="用于查看发送的指令,设备是否已经响应" placement="right-start">
<el-button type="success" size="mini" @click="dataSynchronization()" :disabled="form.deviceId==0">数据同步</el-button>
</el-tooltip>
</span>
</el-tab-pane>
<el-tab-pane name="device05">
<span slot="label">
<el-button type="info" size="mini" @click="goBack()" :disabled="!isLoaded">返回列表</el-button>
</span>
</el-tab-pane>
</el-tabs>
</el-card>
</template>
<script>
import productList from "./product-list"
import deviceLog from './device-log';
import deviceUser from './device-user';
import runningStatus from './running-status';
import deviceStatistic from './device-statistic'
import deviceTimer from './device-timer'
import {
loadBMap
} from '../map.js'
import {
getDevice,
addDevice,
updateDevice,
generatorDeviceNum
} from "@/api/iot/device";
export default {
name: "device-edit",
dicts: ['iot_device_status'],
components: {
deviceLog,
deviceUser,
deviceStatistic,
runningStatus,
productList,
deviceTimer,
},
watch: {
activeName(val) {
if (val == "deviceStastic") {
this.$nextTick(() => {
// TODO 重置统计表格的尺寸
})
}
}
},
data() {
return {
// 是否加载完成
isLoaded: false,
// 生成设备编码是否禁用
genDisabled: false,
// 选中选项卡
activeName: 'basic',
// 遮罩层
loading: true,
// 设备状态1=禁用0=不禁用)
deviceStatus: 0,
// 表单参数
form: {
productId: 0,
status: 1,
},
// 图片地址
imageUrl: require('@/assets/images/product.jpg'),
// 地址
baseUrl: process.env.VUE_APP_BASE_API,
// 地图相关
map: null,
local: null,
mk: null,
latitude: '',
longitude: '',
keyWords: '',
// 表单校验
rules: {
deviceName: [{
required: true,
message: "设备名称不能为空",
trigger: "blur"
}],
firmwareVersion: [{
required: true,
message: "固件版本不能为空",
trigger: "blur"
}],
}
};
},
created() {
// 获取设备信息
this.form.deviceId = this.$route.query && this.$route.query.deviceId;
if (this.form.deviceId != 0) {
this.getDevice(this.form.deviceId);
}
// 未加载完,直接返回会报错
setTimeout(() => {
this.isLoaded = true;
}, 2000);
},
methods: {
/** 数据同步*/
dataSynchronization(){
getDevice(this.form.deviceId).then(response => {
this.form = response.data;
// 选项卡切换
this.activeName='runningStatus';
// 禁用状态
if (this.form.status == 2) {
this.deviceStatus = 1;
}
if (this.form.imgUrl != null && this.form.imgUrl != "") {
this.imageUrl = this.form.imgUrl;
}
this.loadMap();
});
},
/**获取设备详情*/
getDevice(deviceId) {
getDevice(deviceId).then(response => {
this.form = response.data;
// 禁用状态
if (this.form.status == 2) {
this.deviceStatus = 1;
}
if (this.form.imgUrl != null && this.form.imgUrl != "") {
this.imageUrl = this.form.imgUrl;
}
this.loadMap();
});
},
/**加载地图*/
loadMap() {
this.$nextTick(() => {
loadBMap().then(() => {
this.getmap();
});
})
},
/** 返回按钮 */
goBack() {
const obj = {
path: "/iot/device",
query: {
t: Date.now(),
pageNum: this.$route.query.pageNum
}
};
this.$tab.closeOpenPage(obj);
this.reset();
},
// 表单重置
reset() {
this.form = {
deviceId: 0,
deviceName: null,
productId: null,
productName: null,
userId: null,
userName: null,
tenantId: null,
tenantName: null,
serialNumber: null,
firmwareVersion: null,
status: 1,
rssi: null,
networkAddress: null,
networkIp: null,
longitude: null,
latitude: null,
activeTime: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
isCustomLocation: 0,
};
this.deviceStatus = 0;
this.resetForm("form");
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.deviceId != 0) {
// 设置设备状态
this.setDeviceStatus();
console.log(this.form);
updateDevice(this.form).then(response => {
this.$modal.alertSuccess("修改成功");
this.open = false;
this.loadMap();
});
} else {
addDevice(this.form).then(response => {
this.$modal.alertSuccess("新增成功, 可以烧录sdk到设备了");
this.open = false;
this.form = response.data;
if (this.form.status == 2) {
this.deviceStatus = 1;
}
this.loadMap();
});
}
}
});
},
/**选择产品 */
selectProduct() {
this.$refs.productList.open = true;
this.$refs.productList.getList();
},
/**获取选中的产品 */
getProductData(product) {
this.form.productId = product.productId;
this.form.productName = product.productName;
console.log(product);
},
// 获取选中的用户
getUserData(user) {
},
// 地图定位
getmap() {
this.map = new BMap.Map('map')
let point = null;
if (this.form.longitude != null && this.form.longitude != "" && this.form.latitude != null && this.form.latitude != "") {
point = new BMap.Point(this.form.longitude, this.form.latitude)
} else {
point = new BMap.Point(116.404, 39.915)
}
this.map.centerAndZoom(point, 19)
this.map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放
this.map.addControl(new BMap.NavigationControl())
// 标注设备位置
this.mk = new BMap.Marker(point)
this.map.addOverlay(this.mk)
this.map.panTo(point)
},
// 设置设备的状态
setDeviceStatus() {
if (this.deviceStatus == 1) {
this.form.status = 2;
} else {
// 禁用状态,启用后状态是离线
if (this.form.status == 2) {
this.form.status = 4;
}
}
},
// 生成随机字母和数字
generateNum() {
this.genDisabled = true;
generatorDeviceNum().then(response => {
this.form.serialNumber = response.data;
this.genDisabled = false;
})
}
}
};
</script>

View File

@@ -0,0 +1,208 @@
<template>
<div style="padding-left:20px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="类型" prop="logType">
<el-select v-model="queryParams.logType" placeholder="请选择类型" clearable size="small">
<el-option v-for="dict in dict.type.iot_device_log_type" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="标识符" prop="identity">
<el-input v-model="queryParams.identity" placeholder="请输入标识符" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="deviceLogList" size="mini">
<el-table-column label="编号" align="center" prop="logId" width="100" />
<el-table-column label="类型" align="center" prop="logType" width="120">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_device_log_type" :value="scope.row.logType" />
</template>
</el-table-column>
<el-table-column label="时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ scope.row.createTime }}</span>
</template>
</el-table-column>
<el-table-column label="动作" align="left" header-align="center" prop="logValue">
<template slot-scope="scope">
<div v-html="formatValueDisplay(scope.row)"></div>
</template>
</el-table-column>
<el-table-column label="标识符" align="center" prop="identity" />
<el-table-column label="备注" header-align="center" align="left" prop="remark">
<template slot-scope="scope">
{{scope.row.remark==null ?"无":scope.row.remark}}
</template>
</el-table-column>
</el-table>
<div style="height:40px;">
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
</div>
</div>
</template>
<script>
import {
listDeviceLog
} from "@/api/iot/deviceLog";
import {
cacheJsonThingsModel
} from "@/api/iot/model";
export default {
name: "DeviceLog",
dicts: ['iot_device_log_type', "iot_yes_no"],
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device后刷新列表
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
this.queryParams.deviceId = this.deviceInfo.deviceId;
this.getList();
// 获取物模型
this.getCacheThingsModdel(this.deviceInfo.productId);
}
}
},
data() {
return {
// 物模型
thingsModel: {},
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备日志表格数据
deviceLogList: [],
queryParams: {
pageNum: 1,
pageSize: 10,
logType: null,
logValue: null,
deviceId: null,
deviceName: null,
identity: null,
isMonitor: null,
},
};
},
created() {
},
methods: {
/** 查询设备日志列表 */
getList() {
this.loading = true;
listDeviceLog(this.queryParams).then(response => {
this.deviceLogList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/deviceLog/export', {
...this.queryParams
}, `deviceLog_${new Date().getTime()}.xlsx`)
},
/** 获取物模型*/
getCacheThingsModdel(productId) {
// 获取缓存的Json物模型
cacheJsonThingsModel(productId).then(response => {
this.thingsModel = JSON.parse(response.data);
});
},
/** 格式化显示数据定义 */
formatValueDisplay(row) {
// 类型1=属性上报2=调用功能3=事件上报4=设备升级5=设备上线6=设备离线)
if (row.logType == 1) {
let propertyItem = this.getThingsModelItem(1, row.identity);
if (propertyItem != "") {
return propertyItem.name + ' <span style="color:#409EFF;">' + this.getThingsModelItemValue(propertyItem, row.logValue) + ' ' + (propertyItem.datatype.unit != undefined ? propertyItem.datatype.unit : '') + '</span>';
}
} else if (row.logType == 2) {
let functionItem = this.getThingsModelItem(2, row.identity);
if (functionItem != "") {
return functionItem.name + ' <span style="color:#409EFF">' + this.getThingsModelItemValue(functionItem, row.logValue) + ' ' + (functionItem.datatype.unit != undefined ? functionItem.datatype.unit : '') + '</span>';
}
} else if (row.logType == 3) {
let eventItem = this.getThingsModelItem(3, row.identity);
if (eventItem != "") {
return eventItem.name + ' <span style="color:#409EFF">' + this.getThingsModelItemValue(eventItem, row.logValue) + ' ' + (eventItem.datatype.unit != undefined ? eventItem.datatype.unit : '') + '</span>';
}
} else if (row.logType == 4) {
return '<span style="font-weight:bold">设备升级</span>';
} else if (row.logType == 5) {
return '<span style="font-weight:bold">设备上线</span>';
} else if (row.logType == 6) {
return '<span style="font-weight:bold">设备离线</span>';
}
return "";
},
/** 获取物模型项中的值*/
getThingsModelItemValue(item, oldValue) {
if (item.datatype.type == "bool") {
if (oldValue == "0") {
return item.datatype.falseText;
} else if (oldValue == "1") {
return item.datatype.trueText;
}
} else if (item.datatype.type == "enum") {
for (let i = 0; i < item.datatype.enumList.length; i++) {
if (oldValue == item.datatype.enumList[i].value) {
return item.datatype.enumList[i].text;
}
}
}
return oldValue;
},
/** 获取物模型中的项*/
getThingsModelItem(type, identity) {
if (type == 1 && this.thingsModel.properties) {
for (let i = 0; i < this.thingsModel.properties.length; i++) {
if (this.thingsModel.properties[i].id == identity) {
return this.thingsModel.properties[i];
}
}
} else if (type == 2 && this.thingsModel.functions) {
for (let i = 0; i < this.thingsModel.functions.length; i++) {
if (this.thingsModel.functions[i].id == identity) {
return this.thingsModel.functions[i];
}
}
} else if (type == 3 && this.thingsModel.events) {
for (let i = 0; i < this.thingsModel.events.length; i++) {
if (this.thingsModel.events[i].id == identity) {
return this.thingsModel.events[i];
}
}
}
return "";
}
}
};
</script>

View File

@@ -0,0 +1,184 @@
<template>
<div style="padding-left:20px;">
<el-row>
<el-col :span="24">
<div v-for="(item,index) in monitorThings" :key="index" style="margin-bottom:50px;">
<el-card shadow="hover" :body-style="{ padding: '10px 0px',overflow:'auto' }">
<div ref="statisticMap" style="height:250px;width:1470px;"></div>
</el-card>
</div>
</el-col>
</el-row>
</div>
</template>
<script>
import * as echarts from 'echarts';
import {
cacheJsonThingsModel
} from "@/api/iot/model";
import {
listMonitor
} from "@/api/iot/deviceLog";
export default {
name: "device-statistic",
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device后
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
this.getCacheThingsModdel(this.deviceInfo.productId);
}
}
},
data() {
return {
// 设备信息
deviceInfo: {},
// 监测物模型
monitorThings: [],
// 图表集合
chart: [],
};
},
mounted() {
},
methods: {
/** 获取物模型*/
getCacheThingsModdel(productId) {
// 获取缓存的Json物模型
cacheJsonThingsModel(productId).then(response => {
let thingsModel = JSON.parse(response.data);
// 筛选监测数据
this.monitorThings = thingsModel.properties.filter(item => item.isMonitor == 1);
// 加载图表
this.$nextTick(function () {
// 绘制图表
this.getStatistic();
// 获取统计数据
this.getStatisticData(this.monitorThings);
});
});
},
/** 获取统计数据 */
getStatisticData(monitorThingsModel) {
for (let i = 0; i < monitorThingsModel.length; i++) {
let queryParams = {};
queryParams.deviceId = this.deviceInfo.deviceId;
queryParams.identity = monitorThingsModel[i].id;
listMonitor(queryParams).then(response => {
let data = response.rows;
// 对象转数组
let dataList=[];
for(let j=0; j<data.length; j++) {
let item=[];
item[0]=data[j].time;
item[1]=data[j].value;
dataList.push(item);
}
this.chart[i].setOption({
series: [{
data:dataList
}]
});
});
}
},
/**监测统计数据 */
getStatistic() {
for (let i = 0; i < this.monitorThings.length; i++) {
this.chart[i] = echarts.init(this.$refs.statisticMap[i]);
var option;
option = {
animationDurationUpdate:3000,
tooltip: {
trigger: 'axis',
},
title: {
left: 'center',
text: this.monitorThings[i].name + '统计 (单位 ' + (this.monitorThings[i].datatype.unit != undefined ? this.monitorThings[i].datatype.unit : "无") + "",
},
grid: {
top: '80px',
left: '40px',
right: '80px',
bottom: '60px',
containLabel: true
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: 'none'
},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'time',
boundaryGap: false,
name: "时间", //坐标名字
nameLocation: "end", //坐标位置支持start,endmiddle
nameTextStyle: { //字体样式
fontSize: 16, //字体大小
padding: 20 //距离坐标位置的距离
},
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
name: this.monitorThings[i].name, //坐标名字
nameLocation: "end", //坐标位置支持start,endmiddle
nameTextStyle: { //字体样式
fontSize: 16, //字体大小
padding: 10 //距离坐标位置的距离
},
},
dataZoom: [{
type: 'inside',
start: 0,
end: 100
},
{
start: 0,
end: 100
}
],
series: [{
name: this.monitorThings[i].name,
type: 'line',
symbol: 'none',
sampling: 'lttb',
itemStyle: {
color: 'rgb(64, 158, 255)'
},
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgb(64, 158, 255)'
},
{
offset: 1,
color: 'rgb(255, 255, 255)'
}
])
},
data: []
}]
};
option && this.chart[i].setOption(option);
}
},
}
};
</script>

View File

@@ -0,0 +1,808 @@
<template>
<div style="padding-left:20px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="70px">
<el-form-item label="定时名称" prop="jobName">
<el-input v-model="queryParams.jobName" placeholder="请输入定时名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="定时状态" prop="status" style="margin-left:20px;">
<el-select v-model="queryParams.status" placeholder="请选择定时状态" clearable size="small">
<el-option v-for="dict in dict.type.sys_job_status" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['iot:job:add']">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['iot:job:edit']">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['iot:job:remove']">删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['iot:job:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange" size="mini">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="名称" align="center" prop="jobName" :show-overflow-tooltip="true" />
<el-table-column label="描述" align="center" prop="cronText">
<template slot-scope="scope">
<div v-html="formatCronDisplay(scope.row)"></div>
</template>
</el-table-column>
<el-table-column label="CRON表达式" align="center" prop="cronExpression" :show-overflow-tooltip="true" />
<el-table-column label="动作" align="left" prop="actions" :show-overflow-tooltip="true">
<template slot-scope="scope">
<div v-html="formatActionsDisplay(scope.row.actions)"></div>
</template>
</el-table-column>
<el-table-column label="状态" align="center">
<template slot-scope="scope">
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1" active-text="启用" @change="handleStatusChange(scope.row)"></el-switch>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:job:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-caret-right" @click="handleView(scope.row)" v-hasPermi="['iot:job:query']">定时详细</el-button><br />
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:job:remove']">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-caret-right" @click="handleRun(scope.row)" v-hasPermi="['iot:job:changeStatus']">执行一次</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 添加或修改定时定时对话框 -->
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<el-col :span="15">
<el-form-item label="定时名称" prop="jobName">
<el-input v-model="form.jobName" placeholder="请输入定时名称" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="执行时间" prop="timerTimeValue">
<el-time-picker v-model="timerTimeValue" value-format="HH:mm" placeholder="选择时间" style="width:354px;" @change="timeChange" :disabled="form.isAdvance==1"></el-time-picker>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="重复执行" prop="timerWeek">
<el-row>
<el-col :span="4">
<el-select v-model="timerRepeatValue" placeholder="请选择" @change="repeatChange" :disabled="form.isAdvance==1">
<el-option v-for="item in timerRepeats" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-col>
<el-col :span="15" :offset="1" v-if="timerRepeatValue==2">
<el-select v-model="timerWeekValue" placeholder="请选择" multiple style="width:485px" @change="weekChange" :disabled="form.isAdvance==1">
<el-option v-for="item in timerWeeks" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-col>
</el-row>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="cron表达式" prop="">
<el-row>
<el-col :span="18">
<el-input v-model="form.cronExpression" placeholder="cron执行表达式" :disabled="form.isAdvance==0">
<template slot="append">
<el-button type="primary" @click="handleShowCron" :disabled="form.isAdvance==0">
生成表达式
<i class="el-icon-time el-icon--right"></i>
</el-button>
</template>
</el-input>
</el-col>
<el-col :span="4" :offset="1">
<el-checkbox v-model="form.isAdvance" :true-label="1" :false-label="0" @change="customerCronChange">自定义表达式</el-checkbox>
</el-col>
</el-row>
</el-form-item>
</el-col>
<el-col :span="24">
<div style="padding-bottom:15px;padding:0 20px;">
<el-divider></el-divider>
</div>
<el-form-item label="执行动作">
<el-row v-for="(actionItem,index) in actionList" :key="index+'action'" style="margin-bottom:10px;">
<el-col :span="4">
<el-select v-model="actionItem.type" placeholder="请选择类别">
<el-option v-for="(subItem,subIndex) in modelTypes" :key="subIndex+'type'" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="4" :offset="1">
<el-select v-model="actionItem.id" placeholder="请选择" v-if="actionItem.type==1" @change="thingsModelItemChange($event,index)">
<el-option v-for="(subItem,subIndex) in thingsModel.properties" :key="subIndex+'property'" :label="subItem.name" :value="subItem.id">
</el-option>
</el-select>
<el-select v-model="actionItem.id" placeholder="请选择" v-else-if="actionItem.type==2" @change="thingsModelItemChange($event,index)">
<el-option v-for="(subItem,subIndex) in thingsModel.functions" :key="subIndex+'func'" :label="subItem.name" :value="subItem.id">
</el-option>
</el-select>
</el-col>
<el-col :span="10" :offset="1">
<!--物模型项的值-->
<span v-if="actionItem.thingsModelItem &&(actionItem.thingsModelItem.datatype.type=='integer' || actionItem.thingsModelItem.datatype.type=='decimal')">
<el-input style="width:180px;" v-model="actionItem.value" placeholder="值" :max="actionItem.thingsModelItem.datatype.max" :min="actionItem.thingsModelItem.datatype.min" type="number" />
<el-input style="width:70px;margin-left:15px;" v-model="actionItem.thingsModelItem.datatype.unit" placeholder="请输入整数或小数" disabled />
</span>
<span v-else-if=" actionItem.thingsModelItem && actionItem.thingsModelItem.datatype.type=='bool'">
<el-switch v-model="actionItem.value" :active-text="actionItem.thingsModelItem.datatype.trueText" :inactive-text="actionItem.thingsModelItem.datatype.falseText" active-value="1" inactive-value="0">
</el-switch>
</span>
<span v-else-if="actionItem.thingsModelItem && actionItem.thingsModelItem.datatype.type=='enum'">
<el-select v-model="actionItem.value" placeholder="请选择" style="width:100%">
<el-option v-for="(subItem,subIndex) in actionItem.thingsModelItem.datatype.enumList" :key="subIndex+'things'" :label="subItem.text" :value="subItem.value">
</el-option>
</el-select>
</span>
<span v-else-if="actionItem.thingsModelItem && actionItem.thingsModelItem.datatype.type=='string'">
<el-input v-model="actionItem.value" placeholder="请输入字符串" :max="actionItem.thingsModelItem.datatype.maxLength" />
</span>
<span v-else-if="actionItem.thingsModelItem && actionItem.thingsModelItem.datatype.type=='array'">
<el-input v-model="actionItem.value" placeholder="请输入英文逗号分隔的数组" />
</span>
</el-col>
<el-col :span="2" :offset="1" v-if="index!=0"><a style="color:#F56C6C" @click="removeEnumItem(index)">删除</a></el-col>
</el-row>
<div>+ <a style="color:#409EFF" @click="addEnumItem()">添加执行动作</a></div>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="定时状态">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in dict.type.sys_job_status" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" :loading="submitButtonLoading"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<el-dialog title="Cron表达式生成器" :visible.sync="openCron" append-to-body destroy-on-close class="scrollbar">
<crontab @hide="openCron=false" @fill="crontabFill" :expression="expression" style="padding-bottom:80px;"></crontab>
</el-dialog>
<!-- 定时日志详细 -->
<el-dialog title="定时详细" :visible.sync="openView" width="700px" append-to-body>
<el-form ref="form" :model="form" label-width="120px" size="mini">
<el-row>
<el-col :span="12">
<el-form-item label="定时编号:">{{ form.jobId }}</el-form-item>
<el-form-item label="定时名称:">{{ form.jobName }}</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="定时分组:">{{ jobGroupFormat(form) }}</el-form-item>
<el-form-item label="创建时间:">{{ form.createTime }}</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="是否并发:">
<div v-if="form.concurrent == 0">允许</div>
<div v-else-if="form.concurrent == 1">禁止</div>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="cron表达式">{{ form.cronExpression }}</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="执行策略:">
<div v-if="form.misfirePolicy == 0">默认策略</div>
<div v-else-if="form.misfirePolicy == 1">立即执行</div>
<div v-else-if="form.misfirePolicy == 2">执行一次</div>
<div v-else-if="form.misfirePolicy == 3">放弃执行</div>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="下次执行时间:">{{ parseTime(form.nextValidTime) }}</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="定时状态:">
<div v-if="form.status == 0">正常</div>
<div v-else-if="form.status == 1">暂停</div>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="执行动作:">
<div v-html="formatActionsDisplay(form.actions)" style="border:1px solid #ddd;padding:10px;border-radius:5px;width:465px;"></div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="openView = false"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
listJob,
getJob,
delJob,
addJob,
updateJob,
runJob,
changeJobStatus
} from "@/api/iot/deviceJob";
import Crontab from '@/components/Crontab'
import {
cacheJsonThingsModel
} from "@/api/iot/model";
export default {
components: {
Crontab
},
name: "device-timer",
dicts: ['sys_job_group', 'sys_job_status'],
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device后
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
// 获取缓存的Json物模型
cacheJsonThingsModel(this.deviceInfo.productId).then(response => {
this.thingsModel = JSON.parse(response.data);
// 过滤监测数据,监测数据为只读
this.thingsModel.properties = this.thingsModel.properties.filter(item => item.isMonitor == 0);
this.queryParams.deviceId= this.deviceInfo.deviceId;
this.getList();
});
}
}
},
data() {
return {
// 物模型JSON
thingsModel: {},
// 动作列表
actionList: [],
// 设备
deviceInfo: {},
// 遮罩层
loading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 定时定时表格数据
jobList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 是否显示详细弹出层
openView: false,
// 是否显示Cron表达式弹出层
openCron: false,
// 传入的表达式
expression: "",
// 提交按钮加载
submitButtonLoading: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
deviceId:0,
jobName: undefined,
jobGroup: undefined,
status: undefined
},
// 重复执行项
timerRepeats: [{
value: 1,
label: '每天'
}, {
value: 2,
label: '指定'
}],
timerRepeatValue: 1,
// 周
timerWeeks: [{
value: 1,
label: '周一'
}, {
value: 2,
label: '周二'
}, {
value: 3,
label: '周三'
}, {
value: 4,
label: '周四'
}, {
value: 5,
label: '周五'
}, {
value: 6,
label: '周六'
}, {
value: 7,
label: '周日'
}],
timerWeekValue: [1, 2, 3, 4, 5, 6, 7],
// 时间
timerTimeValue: '',
// 物模型类别
modelTypes: [{
value: 1,
label: '属性'
}, {
value: 2,
label: '功能'
}],
// 表单参数
form: {},
// 表单校验
rules: {
jobName: [{
required: true,
message: "定时名称不能为空",
trigger: "blur"
}],
actions: [{
required: true,
message: "执行动作不能为空",
trigger: "blur"
}],
cronExpression: [{
required: true,
message: "cron执行表达式不能为空",
trigger: "blur"
}]
}
};
},
created() {
},
methods: {
/** 查询定时定时列表 */
getList() {
this.loading = true;
listJob(this.queryParams).then(response => {
this.jobList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 定时组名字典翻译
jobGroupFormat(row, column) {
return this.selectDictLabel(this.dict.type.sys_job_group, row.jobGroup);
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
jobId: undefined,
jobName: undefined,
cronExpression: undefined,
status: "0",
jobGroup: "DEFAULT", // 定时分组
misfirePolicy: 2, // 1=立即执行2=执行一次3=放弃执行
concurrent: 1, // 是否并发1=禁止0=允许
isAdvance: 0, // 是否详细cron表达式
jobType: 1, // 任务类型 1=设备定时2=设备告警3=场景联动
productId: 0,
productName: "",
sceneId: 0, //场景ID
alertId: 0, // 告警ID
actions: "",
};
this.submitButtonLoading = false;
this.timerRepeatValue = 1;
this.timerWeekValue = [1, 2, 3, 4, 5, 6, 7];
this.timerTimeValue = "";
this.actionList = [{
id: "",
name: "",
value: "",
type: 2, // 1=属性2=功能3=事件5=设备上线6=设备下线
source: 2, // 1=设备2=定时3=告警输出
deviceId: this.deviceInfo.deviceId,
deviceName: this.deviceInfo.deviceName,
alertName: "", // 告警名称 可选
alertLevel: 1, // 告警级别 告警级别1=提醒通知2=轻微问题3=严重警告)
thingsModelItem: {
id: "",
name: "",
datatype: {
type: "",
}
}
}];
// 物模型项,对应actions
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.jobId);
this.single = selection.length != 1;
this.multiple = !selection.length;
},
// 定时状态修改
handleStatusChange(row) {
let text = row.status === "0" ? "启用" : "停用";
this.$modal.confirm('确认要"' + text + '""' + row.jobName + '"定时吗?').then(function () {
return changeJobStatus(row.jobId, row.status);
}).then(() => {
this.$modal.msgSuccess(text + "成功");
}).catch(function () {
row.status = row.status === "0" ? "1" : "0";
});
},
/* 立即执行一次 */
handleRun(row) {
this.$modal.confirm('确认要立即执行一次"' + row.jobName + '"定时吗?').then(function () {
return runJob(row.jobId, row.jobGroup);
}).then(() => {
this.$modal.msgSuccess("执行成功");
}).catch(() => {});
},
/** 定时详细信息 */
handleView(row) {
getJob(row.jobId).then(response => {
this.form = response.data;
this.openView = true;
});
},
/** cron表达式按钮操作 */
handleShowCron() {
this.expression = this.form.cronExpression;
this.openCron = true;
},
/** 确定后回传值 */
crontabFill(value) {
this.form.cronExpression = value;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加定时";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const jobId = row.jobId || this.ids;
getJob(jobId).then(response => {
this.form = response.data;
// actionList赋值
this.actionList = JSON.parse(this.form.actions);
for (let i = 0; i < this.actionList.length; i++) {
if (this.actionList[i].type == 1) {
for (let j = 0; j < this.thingsModel.properties.length; j++) {
if (this.actionList[i].id == this.thingsModel.properties[j].id) {
this.actionList[i].thingsModelItem = this.thingsModel.properties[j];
break;
}
}
} else if (this.actionList[i].type == 2) {
for (let j = 0; j < this.thingsModel.functions.length; j++) {
if (this.actionList[i].id == this.thingsModel.functions[j].id) {
this.actionList[i].thingsModelItem = this.thingsModel.functions[j];
break;
}
}
}
}
if (this.form.isAdvance == 0) {
// 解析执行时间和重复执行项
if (this.form.cronExpression.substring(12) == "1,2,3,4,5,6,7") {
this.timerRepeatValue = 1; // 每天
} else {
this.timerRepeatValue = 2; // 指定
}
let arrayValue = this.form.cronExpression.substring(12).split(",").map(Number);
this.timerWeekValue = arrayValue;
this.timerTimeValue = this.form.cronExpression.substring(5, 7) + ":" + this.form.cronExpression.substring(2, 4)
}
this.open = true;
this.title = "修改定时";
});
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate(valid => {
if (valid) {
// 验证不能为空
if (this.form.isAdvance == 0) {
if (this.timerTimeValue == "" || this.timerTimeValue == null) {
this.$modal.alertError("执行时间不能空");
return;
}
if (this.timerRepeatValue == 2 && (this.timerWeekValue == null || this.timerWeekValue == "")) {
this.$modal.alertError("请选择要执行的星期");
return;
}
} else if (this.form.isAdvance == 1) {
if (this.form.cronExpression == "") {
this.$modal.alertError("cron表达式不能为空");
return;
}
}
for (let i = 0; i < this.actionList.length; i++) {
if (this.actionList[i].id == "" || this.actionList[i].name == "" || this.actionList[i].value == "") {
this.$modal.alertError("执行动作中的选项和值不能为空");
return;
}
}
// 动作
this.actionList[0].deviceId = this.deviceInfo.deviceId;
this.actionList[0].deviceName = this.deviceInfo.deviceName;
// 删除对象中的物模型属性
for (let i = 0; i < this.actionList.length; i++) {
this.$delete(this.actionList[i], 'thingsModelItem');
}
this.form.actions = JSON.stringify(this.actionList);
// 设备信息
this.form.deviceId = this.deviceInfo.deviceId;
this.form.deviceName = this.deviceInfo.deviceName;
this.form.serialNumber = this.deviceInfo.serialNumber;
this.form.productId = this.deviceInfo.productId;
this.form.productName = this.deviceInfo.productName;
console.log("this.form:",this.form);
// 按钮等待后端加载完
this.submitButtonLoading = true;
if (this.form.jobId != undefined) {
updateJob(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.submitButtonLoading = false;
this.open = false;
this.getList();
});
} else {
addJob(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.submitButtonLoading = false;
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const jobIds = row.jobId || this.ids;
this.$modal.confirm('是否确认删除定时定时编号为"' + jobIds + '"的数据项?').then(function () {
return delJob(jobIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/job/export', {
...this.queryParams
}, `job_${new Date().getTime()}.xlsx`)
},
/** 添加枚举项 */
addEnumItem() {
this.actionList.push({
id: "",
name: "",
value: "",
type: 2, // 1=属性2=功能3=事件5=设备上线6=设备下线
source: 2, // 1=设备2=定时3=告警输出
deviceId: this.deviceInfo.deviceId,
deviceName: this.deviceInfo.deviceName,
alertName: "", // 告警名称 可选
alertLevel: 1, // 告警级别 告警级别1=提醒通知2=轻微问题3=严重警告)
thingsModelItem: {
id: "",
name: "",
datatype: {
type: "",
}
}
});
},
/** 删除枚举项 */
removeEnumItem(index) {
this.actionList.splice(index, 1);
},
/** 修改重复事件 **/
repeatChange(data) {
if (data == 1) {
// 每天
this.timerWeekValue = [1, 2, 3, 4, 5, 6, 7];
} else if (data == 2) {
// 指定
this.timerWeekValue = [1, 2, 3, 4, 5, 6, 7];
}
this.gentCronExpression();
},
/** 星期改变事件 **/
weekChange(data) {
this.gentCronExpression();
},
/** 时间改变事件 **/
timeChange(data) {
this.gentCronExpression();
},
/**自定义cron表达式选项改变事件 */
customerCronChange(data) {
if (data == 0) {
this.gentCronExpression();
}
},
/** 生成cron表达式**/
gentCronExpression() {
let hour = "00";
let minute = "00";
if (this.timerTimeValue != null && this.timerTimeValue != "") {
hour = this.timerTimeValue.substring(0, 2);
minute = this.timerTimeValue.substring(3);
}
let week = "*";
if (this.timerWeekValue.length > 0) {
week = this.timerWeekValue;
}
this.form.cronExpression = "0 " + minute + " " + hour + " ? * " + week;
},
/** 物模型项改变事件 **/
thingsModelItemChange(identifier, index) {
this.actionList[index].value = "";
if (this.actionList[index].type == 1) {
//属性
for (let i = 0; i < this.thingsModel.properties.length; i++) {
if (this.thingsModel.properties[i].id == identifier) {
this.actionList[index].name = this.thingsModel.properties[i].name;
this.actionList[index].thingsModelItem = this.thingsModel.properties[i];
break;
}
}
} else if (this.actionList[index].type == 2) {
//事件
for (let i = 0; i < this.thingsModel.functions.length; i++) {
if (this.thingsModel.functions[i].id == identifier) {
this.actionList[index].name = this.thingsModel.functions[i].name;
this.actionList[index].thingsModelItem = this.thingsModel.functions[i];
break;
}
}
}
},
/** 格式化显示动作 */
formatActionsDisplay(json) {
if (json == null || json == "") {
return;
}
let actions = JSON.parse(json);
let result = "";
for (let i = 0; i < actions.length; i++) {
let value = actions[i].value;
if (actions[i].type == 1) {
// 属性
for (let j = 0; j < this.thingsModel.properties.length; j++) {
if (actions[i].id == this.thingsModel.properties[j].id) {
if (this.thingsModel.properties[j].datatype == "decimal" || this.thingsModel.properties[j].datatype == "integer") {
value = actions[i].value + this.thingsModel.properties[j].datatype.unit;
} else if (this.thingsModel.properties[j].datatype == "enum") {
for (let k = 0; k < this.thingsModel.properties[j].datatype.enumList.length; k++) {
if (actions[i].value == this.thingsModel.properties[j].datatype.enumList[k].value) {
value = this.thingsModel.properties[j].datatype.enumList[k].text;
break;
}
}
} else if (this.thingsModel.properties[j].datatype == "bool") {
value = actions[i].value == "1" ? this.thingsModel.properties[j].datatype.trueText : this.thingsModel.properties[j].datatype.falseText;
}
break;
}
}
} else if (actions[i].type == 2) {
// 功能
for (let j = 0; j < this.thingsModel.functions.length; j++) {
if (actions[i].id == this.thingsModel.functions[j].id) {
if (this.thingsModel.functions[j].datatype.type == "decimal" || this.thingsModel.functions[j].datatype.type == "integer") {
value = actions[i].value + this.thingsModel.functions[j].datatype.unit;
} else if (this.thingsModel.functions[j].datatype.type == "enum") {
for (let k = 0; k < this.thingsModel.functions[j].datatype.enumList.length; k++) {
if (actions[i].value == this.thingsModel.functions[j].datatype.enumList[k].value) {
value = this.thingsModel.functions[j].datatype.enumList[k].text;
break;
}
}
} else if (this.thingsModel.functions[j].datatype.type == "bool") {
value = actions[i].value == "1" ? this.thingsModel.functions[j].datatype.trueText : this.thingsModel.functions[j].datatype.falseText;
}
break;
}
}
}
result = result + actions[i].name + "</span><span style=\"color:#F56C6C\">" + value + "</span><br />";
}
return result;
},
/** 格式化显示CRON描述 */
formatCronDisplay(item) {
let result = "";
if (item.isAdvance == 0) {
let time = "<br /><span style=\"color:#F56C6C\">时间 " + item.cronExpression.substring(5, 7) + ":" + item.cronExpression.substring(2, 4) + "</span>";
let week = item.cronExpression.substring(12);
if (week == "1,2,3,4,5,6,7") {
result = "每天 " + time;
} else {
let weekArray = week.split(",");
for (let i = 0; i < weekArray.length; i++) {
if (weekArray[i] == "1") {
result = result + "周一、";
} else if (weekArray[i] == "2") {
result = result + "周二、";
} else if (weekArray[i] == "3") {
result = result + "周三、";
} else if (weekArray[i] == "4") {
result = result + "周四、";
} else if (weekArray[i] == "5") {
result = result + "周五、";
} else if (weekArray[i] == "6") {
result = result + "周六、";
} else if (weekArray[i] == "7") {
result = result + "周日、";
}
}
result = result.substring(0, result.length - 1) + " " + time;
}
} else {
result = "自定义Cron表达式";
}
return result;
},
}
};
</script>

View File

@@ -0,0 +1,230 @@
<template>
<div style="padding-left:20px;">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="selectUser" v-hasPermi="['iot:deviceUser:add']">分享设备</el-button>
</el-col>
<right-toolbar @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="deviceUserList" @selection-change="handleSelectionChange" size="mini">
<el-table-column label="用户昵称" align="center" prop="userName" width="200" />
<el-table-column label="手机号码" align="center" prop="phonenumber" width="200" />
<el-table-column label="设备所有者" align="center" prop="isOwner" width="100">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isOwner" />
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="150">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="left" prop="remark" al />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:deviceUser:edit']" v-if="scope.row.isOwner==0">备注</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:deviceUser:remove']" v-if="scope.row.isOwner==0">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改设备用户对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" rows="8" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- 选择用户 -->
<user-list ref="userList" :device="device" />
</div>
</template>
<script>
import userList from "./user-list"
import {
listDeviceUser,
getDeviceUser,
delDeviceUser,
updateDeviceUser
} from "@/api/iot/deviceuser";
export default {
name: "device-user",
dicts: ['iot_yes_no'],
components: {
userList
},
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device后刷新列表
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
this.queryParams.deviceId = this.deviceInfo.deviceId;
this.getList();
}
}
},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备用户表格数据
deviceUserList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
deviceName: null,
userName: null,
tenantName: null,
isOwner: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
deviceName: [{
required: true,
message: "设备名称不能为空",
trigger: "blur"
}],
userName: [{
required: true,
message: "用户昵称不能为空",
trigger: "blur"
}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询设备用户列表 */
getList() {
this.loading = true;
listDeviceUser(this.queryParams).then(response => {
this.deviceUserList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
deviceId: null,
userId: null,
deviceName: null,
userName: null,
tenantId: null,
tenantName: null,
isOwner: null,
limitNum: null,
delFlag: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.deviceId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加设备用户";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const deviceId = row.deviceId || this.ids
getDeviceUser(deviceId).then(response => {
this.form = response.data;
this.open = true;
this.title = "用户备注";
});
},
/** 提交按钮 */
submitForm() {
if (this.form.deviceId != null) {
updateDeviceUser(this.form).then(response => {
this.$modal.msgSuccess("备注成功");
this.open = false;
this.getList();
});
}
},
/** 删除按钮操作 */
handleDelete(row) {
const deviceIds = row.deviceId || this.ids;
this.$modal.confirm('是否确认删除设备用户编号为"' + deviceIds + '"的数据项?').then(function () {
return delDeviceUser(deviceIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/deviceUser/export', {
...this.queryParams
}, `deviceUser_${new Date().getTime()}.xlsx`)
},
// 选择用户
selectUser() {
this.$refs.userList.openSelectUser = true;
},
}
};
</script>

View File

@@ -0,0 +1,595 @@
<template>
<div style="padding:6px;">
<el-card style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="75px" style="margin-bottom:-20px;">
<el-form-item label="设备名称" prop="deviceName">
<el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="产品名称" prop="productName">
<el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="设备状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择设备状态" clearable size="small">
<el-option v-for="dict in dict.type.iot_device_status" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="激活时间">
<el-date-picker v-model="daterangeActiveTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
<el-form-item style="float:right;">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleEditDevice(0)" v-hasPermi="['iot:device:add']">新增</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card style="padding-bottom:100px;">
<el-row :gutter="30" v-loading="loading">
<el-col :span="6" v-for="(item,index) in deviceList" :key="index" style="margin-bottom:30px;text-align:center;">
<el-card :body-style="{ padding: '20px'}" shadow="always">
<el-row type="flex" :gutter="10" justify="space-between">
<el-col :span="20" style="text-align:left;">
<el-link type="" :underline="false" @click="handleEditDevice(item)" style="font-weight:bold;font-size:16px;line-height:32px;">
<svg-icon icon-class="device" /> {{item.deviceName}}
<el-tag size="mini" type="info">Version {{item.firmwareVersion}}</el-tag>
</el-link>
</el-col>
<el-col :span="4">
<div style="font-size:28px;color:#ccc;">
<svg-icon v-if="item.status==3 && item.rssi >= '-55'" icon-class="wifi_4" />
<svg-icon v-else-if="item.status==3 && item.rssi >= '-70' && item.rssi < '-55' " icon-class="wifi_3" />
<svg-icon v-else-if="item.status==3 && item.rssi >= '-85' && item.rssi < '-70' " icon-class="wifi_2" />
<svg-icon v-else-if="item.status==3 && item.rssi >= '-100' && item.rssi < '-85' " icon-class="wifi_1" />
<svg-icon v-else icon-class="wifi_0" />
</div>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="15">
<div style="text-align:left;line-height:40px;font-size:14px;">
<dict-tag :options="dict.type.iot_device_status" :value="item.status" size="small" style="width:60px;display:inline-block;" />
<el-tag type="success" size="small" v-if="item.isShadow==1">启用影子</el-tag>
<el-tag type="info" size="small" v-else>禁用影子</el-tag>
</div>
<el-descriptions :column="1" size="mini">
<el-descriptions-item label="编号">
{{item.serialNumber}}
</el-descriptions-item>
<el-descriptions-item label="产品">
{{item.productName}}
</el-descriptions-item>
<el-descriptions-item label="激活时间">
{{ parseTime(item.activeTime, '{y}-{m}-{d}') }}
</el-descriptions-item>
</el-descriptions>
</el-col>
<el-col :span="9">
<div style="margin-top:10px;">
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" lazy :preview-src-list="[baseUrl+item.imgUrl]" :src="baseUrl+item.imgUrl" fit="cover" v-if="item.imgUrl!=null && item.imgUrl!=''"></el-image>
<!-- 用于显示本地计算机手机树莓派等设备图片-->
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/esp8266.jpg')]" :src="require('@/assets/images/esp8266.jpg')" fit="cover" v-else-if="item.productName.indexOf('ESP8266')!=-1"></el-image>
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/esp32.jpg')]" :src="require('@/assets/images/esp32.jpg')" fit="cover" v-else-if="item.productName.indexOf('ESP32')!=-1"></el-image>
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/raspberry.jpg')]" :src="require('@/assets/images/raspberry.jpg')" fit="cover" v-else-if="item.productName.indexOf('Raspberry')!=-1"></el-image>
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/telphone.jpg')]" :src="require('@/assets/images/telphone.jpg')" fit="cover" v-else-if="item.productName.indexOf('Phone')!=-1"></el-image>
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/computer.jpg')]" :src="require('@/assets/images/computer.jpg')" fit="cover" v-else-if="item.productName.indexOf('Computer')!=-1"></el-image>
<el-image style="width:100%;height:100px;border:1px solid #ccc;border-radius:5px;" :preview-src-list="[require('@/assets/images/product.jpg')]" :src="require('@/assets/images/product.jpg')" fit="cover" v-else></el-image>
</div>
</el-col>
</el-row>
<el-descriptions :column="2" border size="mini" style="height:82px;margin-top:10px;overflow:hidden;">
<el-descriptions-item v-for="subItem in item.readOnlyList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<span style="white-space: nowrap;text-overflow: ellipsis;width:40px;overflow:hidden;height:40px;">{{subItem.name}}</span>
</template>
<el-link type="primary" :underline="false" style="white-space: nowrap;">{{subItem.shadow==""?"0":subItem.shadow}} {{subItem.unit==null?"":subItem.unit}}</el-link>
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.boolList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-switch v-model="subItem.shadow" @change="publishThingsModel(item,subItem)" :active-value="'1'" :inactive-value="'0'" :disabled="shadowUnEnable(item)" />
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.enumList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-select v-model="subItem.shadow" placeholder="请选择" @change="publishThingsModel(item,subItem)" clearable size="mini" :title="subItem.name" :disabled="shadowUnEnable(item)">
<el-option v-for="children in subItem.enumList" :key="children.value" :label="children.text" :value="children.value" />
</el-select>
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.decimalList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-input v-model="subItem.shadow" :placeholder="'小数:'+subItem.name" size="mini" :title="'小数:'+subItem.name" :disabled="shadowUnEnable(item)">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(item,subItem)" style="font-size:16px;padding:10px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.integerList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-input v-model="subItem.shadow" :placeholder="'整数:'+subItem.name" :title="'整数:'+subItem.name" size="mini" :disabled="shadowUnEnable(item)">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(item,subItem)" style="font-size:16px;padding:10px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.arrayList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-input v-model="subItem.shadow" :placeholder="'数组:'+subItem.name" :title="'数组:'+subItem.name" size="mini" :disabled="shadowUnEnable(item)">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(item,subItem)" style="font-size:16px;padding:10px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<el-descriptions-item v-for="subItem in item.stringList" :key="subItem.id" :contentStyle="{height:'40px'}">
<template slot="label">
<div style="white-space: nowrap;text-overflow:ellipsis;width:40px;overflow:hidden;" :title="subItem.name">{{subItem.name}}</div>
</template>
<el-input v-model="subItem.shadow" :placeholder="'字符串:'+subItem.name" :title="'字符串:'+subItem.name" size="mini" :disabled="shadowUnEnable(item)">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(item,subItem)" style="font-size:16px;padding:10px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
</el-descriptions>
<el-button-group style="margin-top:15px;">
<el-button type="primary" size="mini" icon="el-icon-edit" @click="handleEditDevice(item)" v-hasPermi="['iot:device:edit']">详情 </el-button>
<el-button type="danger" size="mini" icon="el-icon-delete" @click="handleDelete(item)" v-hasPermi="['iot:device:remove']">删除</el-button>
<el-button type="success" size="mini" icon="el-icon-odometer" @click="handleMonitor(item)" v-hasPermi="['iot:device:edit']" :disabled="item.status!=3">实时监测</el-button>
</el-button-group>
</el-card>
</el-col>
</el-row>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<!-- 查看监测数据 -->
<el-dialog title="实时监测" :visible.sync="open" width="800px">
<div style="margin-top:-50px;">
<el-divider></el-divider>
</div>
<el-form :inline="true" label-width="100px">
<el-form-item label="监测间隔(ms)">
<el-tooltip class="item" effect="light" content="取值范围500-10000毫秒" placement="top">
<el-input v-model="monitorInterval" placeholder="请输入监测间隔" type="number" clearable size="small" style="width:180px;" />
</el-tooltip>
</el-form-item>
<el-form-item label="监测次数">
<el-tooltip class="item" effect="light" content="取值方位1-300" placement="top">
<el-input v-model="monitorNumber" placeholder="请输入监测次数" type="number" clearable size="small" style="width:180px;" />
</el-tooltip>
</el-form-item>
<el-form-item>
<el-button type="success" icon="el-icon-refresh" size="mini" @click="updateMonitorParameters()" style="margin-left:30px;" :disabled="monitorDevice.status !=3"> </el-button>
</el-form-item>
</el-form>
<el-row :gutter="20" v-loading="chartLoading" element-loading-text="正在接收设备数据,请耐心等待......" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
<el-col :span="12" v-for="(item,index) in monitorThings" :key="index" style="margin-bottom:20px;">
<el-card shadow="hover" :body-style="{ paddingTop: '10px',marginBottom:'-20px' }">
<div ref="monitor" style="height:210px;padding:0"></div>
</el-card>
</el-col>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
<!-- Mqtt通讯 -->
<mqtt-client ref="mqttClient" :publish="publish" :subscribes="subscribes" @callbackEvent="mqttCallback($event)" />
</el-card>
</div>
</template>
<script>
import * as echarts from 'echarts';
import {
listDeviceShort,
delDevice,
} from "@/api/iot/device";
import {
cacheJsonThingsModel
} from "@/api/iot/model";
export default {
name: "Device",
dicts: ['iot_device_status', 'iot_is_enable'],
data() {
return {
// 实时监测间隔
monitorInterval: 1000,
// 实时监测次数
monitorNumber: 30,
// 选中的实时监测设备
monitorDevice: {},
// 发布消息
publish: {},
// 订阅集合
subscribes: [],
// 图表集合
chart: [],
// 图表数据集合
dataList: [],
// 监测物模型
monitorThings: [],
// mqtt客户端
client: {},
// 遮罩层
loading: true,
// 图表遮罩层
chartLoading: true,
// 总条数
total: 0,
// 设备列表数据
deviceList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 激活时间范围
daterangeActiveTime: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
deviceName: null,
productId: null,
groupId: null,
productName: null,
userId: null,
userName: null,
tenantId: null,
tenantName: null,
serialNumber: null,
status: null,
networkAddress: null,
activeTime: null,
},
};
},
created() {
this.getList();
},
activated() {
const time = this.$route.query.t;
if (time != null && time != this.uniqueId) {
this.uniqueId = time;
this.queryParams.pageNum = Number(this.$route.query.pageNum);
// 产品筛选
let productId = this.$route.query.productId
if (productId != null) {
this.queryParams.productId = Number(productId);
}
this.getList();
}
},
methods: {
/** 发布物模型 类型(1=属性2=功能) */
publishThingsModel(device, model) {
// 获取缓存的Json物模型
cacheJsonThingsModel(device.productId).then(response => {
let thingsModel = JSON.parse(response.data);
let type = 0;
for (let i = 0; i < thingsModel.functions.length; i++) {
if (model.id == thingsModel.functions[i].id) {
type = 2;
break;
}
}
if (type == 0) {
for (let i = 0; i < thingsModel.properties.length; i++) {
if (model.id == thingsModel.properties[i].id) {
type = 1;
break;
}
}
}
if (type != 0) {
this.mqttPublish(type, device, model);
}
})
},
/**
* Mqtt发布消息
* @type 类型(1=属性2=功能3=OTA升级4=实时监测)
* @device 设备
* @model 物模型
* */
mqttPublish(type, device, model) {
let topic = "";
let message = ""
if (type == 1) {
if (device.status == 3) {
// 属性,在线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/property-online/get";
} else if (device.isShadow) {
// 属性,离线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/property-offline/post";
}
message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
} else if (type == 2) {
if (device.status == 3) {
// 功能,在线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/function-online/get";
} else if (device.isShadow) {
// 功能,离线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/function-offline/post";
}
message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
} else if (type == 3) {
// OTA升级
topic = "/" + device.productId + "/" + device.serialNumber + "/ota/get";
message = '{"version":1.1}';
} else if (type == 4) {
// 实时监测
topic = "/" + device.productId + "/" + device.serialNumber + "/monitor/get";
message = '{"count":' + model.value + ',"interval":' + this.monitorInterval + '}'
} else {
return;
}
if (topic != "") {
// 发布
this.publish = {
topic: topic,
message: message
};
if (model.name != "") {
this.$modal.notifySuccess("[ " + model.name + " ] 指令发送成功");
}
}
},
/** 接收到Mqtt回调 */
mqttCallback(data) {
let topics = [];
topics = data.topic.split("/");
let productId = topics[1];
let deviceNum = topics[2]
if (topics[3] == "status") {
// 更新列表中设备的状态
for (let i = 0; i < this.deviceList.length; i++) {
if (this.deviceList[i].serialNumber == deviceNum) {
this.deviceList[i].status = data.message.status;
this.deviceList[i].isShadow = data.message.isShadow;
}
}
// 更新实时监测模型的状态
if (this.monitorDevice.serialNumber == deviceNum) {
this.monitorDevice.status = data.message.status;
this.monitorDevice.isShadow = data.message.isShadow;
}
} else if (topics[3] == "monitor") {
// 实时监测
this.chartLoading = false;
for (let k = 0; k < data.message.length; k++) {
let value = data.message[k].value;
let id = data.message[k].id;
let remark = data.message[k].remark;
// 数据加载到图表
for (let i = 0; i < this.dataList.length; i++) {
if (id == this.dataList[i].id) {
if (this.dataList[i].length > 50) {
this.dataList[i].shift();
}
this.dataList[i].data.push([this.getTime(), value]);
// 更新图表
this.chart[i].setOption({
series: [{
data: this.dataList[i].data
}]
});
}
}
}
}
},
/** Mqtt订阅主题 */
mqttSubscribe(list) {
// 订阅当前页面设备状态和实时监测
let topics = [];
for (let i = 0; i < list.length; i++) {
let topicStatus = "/" + list[i].productId + "/" + list[i].serialNumber + "/status/post";
let topicMonitor = "/" + list[i].productId + "/" + list[i].serialNumber + "/monitor/post";
topics.push(topicStatus);
topics.push(topicMonitor);
}
this.subscribes = topics;
},
/** 更新实时监测参数*/
updateMonitorParameters() {
// 清空图表数据
for (let i = 0; i < this.dataList.length; i++) {
this.dataList[i].data = [];
}
if (this.monitorInterval < 500 || this.monitorInterval > 10000) {
this.$modal.alertError("实时监测的间隔范围500-10000毫秒");
}
if (this.monitorNumber == 0 || this.monitorNumber > 300) {
this.$modal.alertError("实时监测数量范围1-300");
}
// Mqtt发布实时监测消息
let model = {};
model.name = "更新实时监测";
model.value = this.monitorNumber;
this.mqttPublish(4, this.monitorDevice, model);
this.chartLoading = true;
},
/** 查看监测数据 */
handleMonitor(item) {
this.open = true;
this.monitorLoading = true;
this.monitorDevice = item;
// 获取物模型
this.getCacheThingsModdel(item.productId);
// Mqtt发布实时监测
let model = {};
model.name = "";
model.value = this.monitorNumber;
this.mqttPublish(4, item, model);
},
/** 停止实时监测 */
stopMonitor() {
// 清空图表数据
this.dataList = [];
this.chartLoading = true;
// Mqtt发布实时监测
let model = {};
model.name = "";
model.value = 0;
this.mqttPublish(4, this.monitorDevice, model);
},
/** 查询设备列表 */
getList() {
this.loading = true;
if (null != this.daterangeActiveTime && '' != this.daterangeActiveTime) {
this.queryParams.params["beginActiveTime"] = this.daterangeActiveTime[0];
this.queryParams.params["endActiveTime"] = this.daterangeActiveTime[1];
}
listDeviceShort(this.queryParams).then(response => {
this.deviceList = response.rows;
this.total = response.total;
// 订阅设备状态
this.mqttSubscribe(this.deviceList);
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.stopMonitor();
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeActiveTime = [];
this.queryParams.productId = null;
this.resetForm("queryForm");
this.handleQuery();
},
/** 修改按钮操作 */
handleEditDevice(row) {
let deviceId = 0;
if (row != 0) {
deviceId = row.deviceId || this.ids
}
this.$router.push({
path: '/iot/device-edit',
query: {
deviceId: deviceId,
pageNum: this.queryParams.pageNum
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const deviceIds = row.deviceId || this.ids;
this.$modal.confirm('是否确认删除设备编号为"' + deviceIds + '"的数据项?').then(function () {
return delDevice(deviceIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 未启用设备影子*/
shadowUnEnable(item) {
// 1-未激活2-禁用3-在线4-离线
if (item.status != 3 && item.isShadow == 0) {
return true;
}
return false;
},
/** 获取物模型*/
getCacheThingsModdel(productId) {
// 获取缓存的Json物模型
cacheJsonThingsModel(productId).then(response => {
let thingsModel = JSON.parse(response.data);
// 筛选监测数据
this.monitorThings = thingsModel.properties.filter(item => item.isMonitor == 1);
// 监测数据集合初始化
for (let i = 0; i < this.monitorThings.length; i++) {
this.dataList.push({
id: this.monitorThings[i].id,
name: this.monitorThings[i].name,
data: []
});
// this.dataList[i].data.push(["2022-03-14 23:32:09", "30"]);
}
// 绘制监测图表
this.$nextTick(function () {
this.getMonitorChart();
});
});
},
/**监测数据 */
getMonitorChart() {
for (let i = 0; i < this.monitorThings.length; i++) {
this.chart[i] = echarts.init(this.$refs.monitor[i]);
var option;
option = {
title: {
left: 'center',
text: this.monitorThings[i].name + ' 单位 ' + (this.monitorThings[i].datatype.unit != undefined ? this.monitorThings[i].datatype.unit : "无") + "",
textStyle: {
fontSize: 14,
}
},
grid: {
top: '40px',
left: '20px',
right: '20px',
bottom: '10px',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
animation: true
}
},
xAxis: {
type: 'time',
show: false,
splitLine: {
show: false
}
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
splitLine: {
show: true
}
},
series: [{
name: this.monitorThings[i].name,
type: 'line',
showSymbol: false,
data: this.dataList[i].data
}]
};
option && this.chart[i].setOption(option);
}
},
getTime() {
let date = new Date();
let y = date.getFullYear();
let m = date.getMonth() + 1;
let d = date.getDate();
let H = date.getHours();
let mm = date.getMinutes();
let s = date.getSeconds()
m = m < 10 ? "0" + m : m;
d = d < 10 ? "0" + d : d;
H = H < 10 ? "0" + H : H;
return y + "-" + m + "-" + d + " " + H + ":" + mm + ":" + s;
},
}
};
</script>

View File

@@ -0,0 +1,133 @@
<template>
<span></span>
</template>
<script>
import mqtt from 'mqtt'
import {
cacheJsonThingsModel
} from "@/api/iot/model";
import {
getToken
} from "@/utils/auth";
export default {
name: "mqttClient",
props: {
publish: {
type: Object,
default: null
},
subscribes: {
type: Array,
default: null
}
},
watch: {
// 获取到父组件传递的值
publish: function (val, oldVal) {
this.mqttPublish(val.topic, val.message);
},
subscribes: function (val, oldVal) {
this.connectMqtt(val);
}
},
data() {
return {
// 设备信息
deviceInfo: {},
};
},
created() {
},
methods: {
/** 连接Mqtt */
connectMqtt(subscribeTopics) {
let options = {
username: "wumei-smart",
password: getToken(),
cleanSession: false,
keepAlive: 30,
clientId: 'web-' + Math.random().toString(16).substr(2),
connectTimeout: 60000
}
this.client = mqtt.connect(process.env.VUE_APP_BROKEN_URL, options);
this.client.on("connect", (e) => {
console.log("成功连接服务器:", e);
// 订阅主题
this.client.subscribe(subscribeTopics, {
qos: 1
}, (err) => {
if (!err) {
console.log("订阅成功");
console.log(subscribeTopics.join(", "));
} else {
console.log('消息订阅失败!')
}
});
});
// 重新连接
this.reconnectMqtt()
// 是否已经断开连接
this.mqttError()
// 监听获取信息
this.mqttSubscribe()
},
/** 发布消息 */
mqttPublish(topic, message) {
if (!this.client.connected) {
console.log('客户端未连接')
return
}
this.client.publish(topic, message, {
qos: 1
}, (err) => {
if (!err) {
console.log('成功发布主题:' + topic)
console.log('主题内容:' + message);
}
})
},
/** 监听Mqtt消息 */
mqttSubscribe() {
this.client.on("message", (topic, message) => {
console.log('收到来自', topic, '的信息', message.toString())
// 传递信息到父组件
let data = {};
data.topic = topic;
data.message = JSON.parse(message.toString());
this.$emit('callbackEvent', data);
});
},
/** 监听服务器是否连接失败 */
mqttError() {
this.client.on('error', (error) => {
console.log('连接失败:', error)
this.client.end()
})
},
/** 取消订阅 */
unsubscribeMqtt() {
this.client.unsubscribe(this.mtopic, (error) => {
console.log('主题为' + this.mtopic + '取消订阅成功', error)
})
},
/** 断开连接 */
unconnectMqtt() {
this.client.end()
this.client = null
console.log('服务器已断开连接!')
},
/** 监听服务器重新连接 */
reconnectMqtt() {
this.client.on('reconnect', (error) => {
console.log('正在重连:', error)
});
},
}
};
</script>

View File

@@ -0,0 +1,145 @@
<template>
<el-dialog title="选择产品" :visible.sync="open" width="800px">
<div style="margin-top:-55px;">
<el-divider style="margin-top:-30px;"></el-divider>
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<el-form-item label="产品名称" prop="productName">
<el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" ref="singleTable" :data="productList" @current-change="handleCurrentChange" highlight-current-row border size="mini">
<el-table-column label="选择" width="50" align="center">
<template slot-scope="scope">
<input type="radio" :checked="scope.row.isSelect" name="product" />
</template>
</el-table-column>
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="分类名称" align="center" prop="categoryName" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_product_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="联网方式" align="center" prop="networkMethod">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_network_method" :value="scope.row.networkMethod" />
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="150">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="confirmSelectProduct" type="primary">确定</el-button>
<el-button @click="closeDialog" type="info"> </el-button>
</div>
</el-dialog>
</template>
<script>
import {
listProduct,
} from "@/api/iot/product";
export default {
name: "Product",
dicts: [ 'iot_product_status', 'iot_network_method'],
props: {
productId: {
type: Number,
default: 0
}
},
data() {
return {
// 遮罩层
loading: true,
// 总条数
total: 0,
// 打开选择产品对话框
open: false,
// 产品列表
productList: [],
// 选中的产品
product: {},
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
productName: null,
categoryId: null,
categoryName: null,
tenantId: null,
tenantName: null,
isSys: null,
status: 2, //已发布
deviceType: null,
networkMethod: null,
},
};
},
created() {
},
methods: {
/** 查询产品列表 */
getList() {
this.loading = true;
listProduct(this.queryParams).then(response => {
this.productList = response.rows;
this.total = response.total;
if (this.productId != 0) {
this.setRadioSelected(this.productId);
}
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 单选数据 */
handleCurrentChange(product) {
if (product != null) {
this.setRadioSelected(product.productId);
this.product = product;
}
},
/** 设置单选按钮选中 */
setRadioSelected(productId) {
for (let i = 0; i < this.productList.length; i++) {
if (this.productList[i].productId == productId) {
this.productList[i].isSelect = true;
} else {
this.productList[i].isSelect = false;
}
}
},
/**确定选择产品,产品传递给父组件 */
confirmSelectProduct() {
this.$emit('productEvent', this.product);
this.open = false;
},
/**关闭对话框 */
closeDialog() {
this.open = false;
}
}
};
</script>

View File

@@ -0,0 +1,423 @@
<template>
<div style="padding-left:20px;">
<el-row :gutter="80">
<el-col :span="9">
<el-descriptions :column="1" border :title="title">
<!-- 设备升级-->
<el-descriptions-item :labelStyle="statusColor">
<template slot="label">
<svg-icon icon-class="ota" />
OTA升级
</template>
<el-link :underline="false" style="line-height:28px;font-size:16px;padding-right:10px;">Version {{deviceInfo.firmwareVersion}}</el-link>
<el-link type="success" :underline="false" style="font-size:12px;display:none;">已经是最新版本</el-link>
<el-button type="success" size="mini" style="float:right;" @click="otaUpgrade()" :disabled="deviceInfo.status!=3">升级</el-button>
</el-descriptions-item>
<!-- bool类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.boolList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-open"></i>
{{item.name}}
</template>
<el-switch v-model="item.shadow" @change="publishThingsModel(deviceInfo,item)" active-text="" inactive-text="" active-value="1" inactive-value="0" style="min-width:100px;" :disabled="shadowUnEnable" />
</el-descriptions-item>
<!-- enum类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.enumList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-s-unfold"></i>
{{item.name}}
</template>
<el-select v-model="item.shadow" placeholder="请选择" @change="publishThingsModel(deviceInfo,item)" clearable :disabled="shadowUnEnable">
<el-option v-for="subItem in item.enumList" :key="subItem.value" :label="subItem.text" :value="subItem.value" />
</el-select>
</el-descriptions-item>
<!-- string类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.stringList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-tickets"></i>
{{item.name}}
</template>
<el-input v-model="item.shadow" placeholder="请输入字符串" :disabled="shadowUnEnable">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(deviceInfo,item)" style="font-size:20px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<!-- array类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.arrayList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-tickets"></i>
{{item.name}}
</template>
<el-input v-model="item.shadow" placeholder="请输入英文逗号分隔的字符串" :disabled="shadowUnEnable">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(deviceInfo,item)" style="font-size:20px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<!-- decimal类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.decimalList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-star-off"></i>
{{item.name}}
</template>
<el-input v-model="item.shadow" type="number" placeholder="请输入小数 " :disabled="shadowUnEnable">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(deviceInfo,item)" style="font-size:20px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
<!-- integer类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.integerList" :key="index" :labelStyle="statusColor">
<template slot="label">
<i class="el-icon-paperclip"></i>
{{item.name}}
</template>
<el-input v-model="item.shadow" type="integer" placeholder="请输入整数 " :disabled="shadowUnEnable">
<el-button slot="append" icon="el-icon-s-promotion" @click="publishThingsModel(deviceInfo,item)" style="font-size:20px;" title="指令发送"></el-button>
</el-input>
</el-descriptions-item>
</el-descriptions>
<!-- 监测数据-->
<el-descriptions :column="2" border style="margin:40px 0;" title="监测数据">
<el-descriptions-item v-for="(item,index) in deviceInfo.readOnlyList" :key="index">
<template slot="label">
<i class="el-icon-odometer"></i>
{{item.name}}
</template>
<el-link type="primary" :underline="false">{{item.shadow}} {{item.unit==null?"":item.unit}}</el-link>
</el-descriptions-item>
</el-descriptions>
<!---设备状态(影子模式value值不会更新)-->
<el-descriptions :column="1" border size="mini" v-if="deviceInfo.isShadow==1 && deviceInfo.status!=3">
<template slot="title">
<span style="font-size:14px;color:#606266;">设备处于离线状态</span>
</template>
<!-- bool类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.boolList" :key="index">
<template slot="label">
<i class="el-icon-open"></i>
{{item.name}}
</template>
<el-switch v-model="item.value" size="mini" active-text="" inactive-text="" active-value="1" inactive-value="0" style="min-width:100px;" disabled />
</el-descriptions-item>
<!-- enum类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.enumList" :key="index">
<template slot="label">
<i class="el-icon-s-unfold"></i>
{{item.name}}
</template>
<el-select v-model="item.value" placeholder="请选择" clearable size="mini" disabled >
<el-option v-for="subItem in item.enumList" :key="subItem.value" :label="subItem.text" :value="subItem.value" />
</el-select>
</el-descriptions-item>
<!-- string类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.stringList" :key="index">
<template slot="label">
<i class="el-icon-tickets"></i>
{{item.name}}
</template>
<el-input v-model="item.value" placeholder="请输入字符串" size="mini" disabled></el-input>
</el-descriptions-item>
<!-- array类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.arrayList" :key="index">
<template slot="label">
<i class="el-icon-tickets"></i>
{{item.name}}
</template>
<el-input v-model="item.value" placeholder="请输入英文逗号分隔的字符串" size="mini" disabled></el-input>
</el-descriptions-item>
<!-- decimal类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.decimalList" :key="index">
<template slot="label">
<i class="el-icon-star-off"></i>
{{item.name}}
</template>
<el-input v-model="item.value" type="number" placeholder="请输入小数" size="mini" disabled></el-input>
</el-descriptions-item>
<!-- integer类型-->
<el-descriptions-item v-for="(item,index) in deviceInfo.integerList" :key="index">
<template slot="label">
<i class="el-icon-paperclip"></i>
{{item.name}}
</template>
<el-input v-model="item.value" type="integer" placeholder="请输入整数 " size="mini" disabled></el-input>
</el-descriptions-item>
</el-descriptions>
<!-- Mqtt通讯 -->
<mqtt-client ref="mqttClient" :publish="publish" :subscribes="subscribes" @callbackEvent="mqttCallback($event)" />
</el-col>
<el-col :span="14" :offset="1">
<el-row :gutter="20" style="background-color:#F5F7FA;padding:20px;padding-left:10px;">
<el-col :span="8" v-for="(item,index) in deviceInfo.readOnlyList" :key="index" style="margin-bottom:20px;">
<el-card shadow="hover" style="border-radius:30px;">
<div ref="map" style="height:230px;width:180px;margin:0 auto;margin-top:-10px;"></div>
</el-card>
</el-col>
</el-row>
</el-col>
</el-row>
</div>
</template>
<script>
import {
getDeviceRunningStatus
} from "@/api/iot/device"
import {
cacheJsonThingsModel
} from "@/api/iot/model";
import * as echarts from 'echarts';
export default {
name: "running-status",
dicts: ['iot_yes_no'],
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device后刷新列表
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (this.deviceInfo && this.deviceInfo.deviceId != 0) {
getDeviceRunningStatus(this.deviceInfo.deviceId).then(response => {
this.deviceInfo = response.data;
this.updateDeviceStatus(this.deviceInfo);
this.$nextTick(function () {
this.MonitorChart();
});
// Mqtt订阅主题
this.mqttSubscribe(this.deviceInfo);
});
}
}
},
data() {
return {
// 发布消息
publish: {},
// 订阅集合
subscribes: [],
// 控制模块标题
title: "设备控制 ",
// 未启用设备影子
shadowUnEnable: false,
// 控制项标题背景
statusColor: {
background: '#67C23A',
color: '#fff',
},
// 遮罩层
loading: true,
// 设备信息
deviceInfo: {
boolList: [],
enumList: [],
stringList: [],
integerList: [],
decimalList: [],
arrayList: [],
readonlyList: []
},
}
},
created() {
},
methods: {
/** 发布物模型 类型(1=属性2=功能) */
publishThingsModel(device, model) {
// 获取缓存的Json物模型
cacheJsonThingsModel(device.productId).then(response => {
let thingsModel = JSON.parse(response.data);
let type = 0;
for (let i = 0; i < thingsModel.functions.length; i++) {
if (model.id == thingsModel.functions[i].id) {
type = 2;
break;
}
}
if (type == 0) {
for (let i = 0; i < thingsModel.properties.length; i++) {
if (model.id == thingsModel.properties[i].id) {
type = 1;
break;
}
}
}
if (type != 0) {
this.mqttPublish(type, device, model);
}
})
},
/**
* Mqtt发布消息
* @type 类型(1=属性2=功能3=OTA升级4=实时监测)
* @device 设备
* @model 物模型
* */
mqttPublish(type, device, model) {
let topic = "";
let message = ""
if (type == 1) {
if (device.status == 3) {
// 属性,在线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/property-online/get";
} else if (device.isShadow) {
// 属性,离线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/property-offline/post";
}
message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
} else if (type == 2) {
if (device.status == 3) {
// 功能,在线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/function-online/get";
} else if (device.isShadow) {
// 功能,离线模式
topic = "/" + device.productId + "/" + device.serialNumber + "/function-offline/post";
}
message = '[{"id":"' + model.id + '","value":"' + model.shadow + '"}]';
} else if (type == 3) {
// OTA升级
topic = "/" + device.productId + "/" + device.serialNumber + "/ota/get";
message = '{"version":' + device.firmwareVersion + '}';
} else {
return;
}
if (topic != "") {
// 发布
this.publish = {
topic: topic,
message: message
}
if (model) {
this.$modal.notifySuccess("[ " + model.name + " ] 指令发送成功");
}
}
},
/** 接收到Mqtt回调 */
mqttCallback(data) {
let topics = [];
topics = data.topic.split("/");
let productId = topics[1];
let deviceNum = topics[2]
if (topics[3] == "status") {
// 更新列表中设备的状态
this.deviceInfo.status = data.message.status;
this.deviceInfo.isShadow = data.message.isShadow;
this.updateDeviceStatus(this.deviceInfo);
}
},
/** Mqtt订阅主题 */
mqttSubscribe(device) {
// 订阅当前设备状态
let topic = "/" + device.productId + "/" + device.serialNumber + "/status/post";
this.subscribes = [topic];
},
/** 更新设备状态 */
updateDeviceStatus(device) {
if (device.status == 3) {
this.statusColor.background = '#67C23A';
this.title = "设备控制(在线)";
} else {
if (device.isShadow == 1) {
this.statusColor.background = '#409EFF';
this.title = "设备控制(影子模式)";
} else {
this.statusColor.background = '#909399';
this.title = "设备控制(设备不在线 未启用影子)";
this.shadowUnEnable = true;
}
}
},
/** 设备升级 */
otaUpgrade() {
let model = {};
model.name = "设备升级"
this.mqttPublish(3, this.deviceInfo, model);
},
/**监测图表*/
MonitorChart() {
for (let i = 0; i < this.deviceInfo.readOnlyList.length; i++) {
var myChart = echarts.init(this.$refs.map[i]);
var option;
option = {
tooltip: {
formatter: ' {b} <br/> {c}' + this.deviceInfo.readOnlyList[i].unit
},
series: [{
name: this.deviceInfo.readOnlyList[i].type,
type: 'gauge',
min: this.deviceInfo.readOnlyList[i].min,
max: this.deviceInfo.readOnlyList[i].max,
colorBy: 'data',
splitNumber: 10,
radius: '100%',
// 分割线
splitLine: {
distance: 4,
},
axisLabel: {
fontSize: 10,
distance: 10
},
// 刻度线
axisTick: {
distance: 4,
},
// 仪表盘轴线
axisLine: {
lineStyle: {
width: 8,
color: [
[0.3, '#409EFF'], // 0~30%
[0.7, '#67C23A'], // 30~70%
[1, '#F56C6C'], // 70~100%
],
opacity: 0.3
}
},
pointer: {
icon: 'triangle',
length: '60%',
width: 7
},
progress: {
show: true,
width: 8,
},
detail: {
valueAnimation: true,
formatter: '{value}' + ' ' + this.deviceInfo.readOnlyList[i].unit,
offsetCenter: [0, "80%"],
fontSize: 20,
},
data: [{
value: this.deviceInfo.readOnlyList[i].shadow,
name: this.deviceInfo.readOnlyList[i].name
}],
title: {
offsetCenter: [0, "115%"],
fontSize: 16
}
}]
};
option && myChart.setOption(option);
}
}
},
}
</script>

View File

@@ -0,0 +1,168 @@
<template>
<el-dialog title="选择产品" :visible.sync="openSelectUser" width="800px">
<div style="margin-top:-50px;">
<el-divider></el-divider>
</div>
<!--用户数据-->
<el-form :model="queryParams" ref="queryForm" :rules="rules" :inline="true" label-width="80px">
<el-form-item label="手机号码" prop="phonenumber">
<el-input type="text" placeholder="请输入用户手机号码" v-model="queryParams.phonenumber" minlength="10" clearable size="small" show-word-limit style="width: 240px" @keyup.enter.native="handleQuery"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="userList" highlight-current-row size="mini" @current-change="handleCurrentChange" border>
<el-table-column label="选择" width="50" align="center">
<template slot-scope="scope">
<input type="radio" :checked="scope.row.isSelect" name="user" />
</template>
</el-table-column>
<el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" />
<el-table-column label="手机号码" align="center" key="phonenumber" prop="phonenumber" width="120" />
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="addDeviceUser">添加</el-button>
<el-button @click="closeSelectUser"> </el-button>
</div>
</el-dialog>
</template>
<script>
import {
listUser
} from "@/api/system/user";
import {
addDeviceUser,
} from "@/api/iot/deviceuser";
export default {
name: "user-list",
props: {
device: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的device
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
}
},
data() {
return {
// 遮罩层
loading: false,
// 选中数组
ids: [],
// 弹出层标题
title: "",
// 用户列表
userList: [],
// 选中的用户
user: {},
// 设备信息
deviceInfo: {},
// 是否显示选择用户弹出层
openSelectUser: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
userName: undefined,
phonenumber: undefined,
status: 0,
deptId: undefined
},
// 表单校验
rules: {
phonenumber: [{
required: true,
message: "手机号码不能为空",
trigger: "blur"
}, {
min: 11,
max: 11,
message: '手机号码长度为11位',
trigger: 'blur'
}],
},
};
},
created() {},
methods: {
/** 查询用户列表 */
getList() {
this.loading = true;
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery() {
this.$refs["queryForm"].validate(valid => {
if (valid) {
this.queryParams.pageNum = 1;
this.getList();
}
});
},
// 重置查询
resetQuery() {
this.$refs["queryForm"].resetFields();
this.userList = [];
},
//设置单选按钮选中
setRadioSelected(userId) {
for (let i = 0; i < this.userList.length; i++) {
if (this.userList[i].userId == userId) {
this.userList[i].isSelect = true;
this.user = this.userList[i];
} else {
this.userList[i].isSelect = false;
}
}
},
// 单选数据
handleCurrentChange(user) {
if (user != null) {
this.setRadioSelected(user.userId);
this.user = user;
}
},
// 关闭选择用户
closeSelectUser() {
this.openSelectUser = false;
this.resetQuery();
},
// 添加设备用户
addDeviceUser() {
if (this.deviceInfo.deviceId != null) {
var form = {};
form.deviceId = this.deviceInfo.deviceId;
form.deviceName = this.deviceInfo.deviceName;
form.userId = this.user.userId;
form.userName = this.user.userName;
form.phonenumber=this.user.phonenumber;
addDeviceUser(form).then(response => {
this.$modal.msgSuccess("新增成功");
this.resetQuery();
this.openSelectUser = false;
this.$parent.getList();
});
}
},
}
};
</script>