发布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,266 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="告警名称" prop="alertName">
<el-input v-model="queryParams.alertName" placeholder="请输入告警名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="告警级别" prop="alertLevel">
<el-select v-model="queryParams.alertLevel" placeholder="请选择告警级别" clearable size="small">
<el-option v-for="dict in dict.type.iot_alert_level" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</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_process_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-card>
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="alertLogList" @selection-change="handleSelectionChange" border>
<el-table-column label="告警名称" align="center" prop="alertName" />
<el-table-column label="告警级别" align="center" prop="alertLevel">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_alert_level" :value="scope.row.alertLevel" />
</template>
</el-table-column>
<el-table-column label="处理状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_process_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="产品ID" align="center" prop="productId" />
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="设备ID" align="center" prop="deviceId" />
<el-table-column label="设备名称" align="center" prop="deviceName" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="处理结果" align="center" prop="remark" />
<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:alertLog:edit']">处理</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="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>
</el-card>
</div>
</template>
<script>
import {
listAlertLog,
getAlertLog,
delAlertLog,
addAlertLog,
updateAlertLog
} from "@/api/iot/alertLog";
export default {
name: "AlertLog",
dicts: ['iot_alert_level', 'iot_process_status'],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备告警表格数据
alertLogList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
alertName: null,
alertLevel: null,
status: null,
productId: null,
productName: null,
deviceId: null,
deviceName: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
alertName: [{
required: true,
message: "告警名称不能为空",
trigger: "blur"
}],
alertLevel: [{
required: true,
message: "告警级别不能为空",
trigger: "change"
}],
status: [{
required: true,
message: "处理状态(0=不需要处理,1=未处理,2=已处理)不能为空",
trigger: "change"
}],
productId: [{
required: true,
message: "产品ID不能为空",
trigger: "blur"
}],
productName: [{
required: true,
message: "产品名称不能为空",
trigger: "blur"
}],
deviceId: [{
required: true,
message: "设备ID不能为空",
trigger: "blur"
}],
deviceName: [{
required: true,
message: "设备名称不能为空",
trigger: "blur"
}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询设备告警列表 */
getList() {
this.loading = true;
listAlertLog(this.queryParams).then(response => {
this.alertLogList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
alertLogId: null,
alertName: null,
alertLevel: null,
status: null,
productId: null,
productName: null,
deviceId: null,
deviceName: 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.alertLogId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加设备告警";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const alertLogId = row.alertLogId || this.ids
getAlertLog(alertLogId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改设备告警";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.alertLogId != null) {
updateAlertLog(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addAlertLog(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const alertLogIds = row.alertLogId || this.ids;
this.$modal.confirm('是否确认删除设备告警编号为"' + alertLogIds + '"的数据项?').then(function () {
return delAlertLog(alertLogIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/alertLog/export', {
...this.queryParams
}, `alertLog_${new Date().getTime()}.xlsx`)
}
}
};
</script>

View File

@@ -0,0 +1,262 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="queryParams.categoryName" placeholder="请输入产品分类名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="系统定义" prop="isSys">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
<el-option v-for="dict in dict.type.iot_yes_no" :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-card>
<el-card style="padding-bottom:100px;">
<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:category: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:category: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:category: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:category:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="categoryList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="产品分类名称" align="center" prop="categoryName" />
<el-table-column label="备注" align="left" prop="remark" min-width="150" />
<el-table-column label="系统定义" align="center" prop="isSys">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isSys" />
</template>
</el-table-column>
<el-table-column label="显示顺序" align="center" prop="orderNum" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="small" type="primary" style="padding:5px;" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:category:edit']">修改</el-button>
<el-button size="small" type="danger" style="padding:5px;" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:category:remove']">删除</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="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" type="number" placeholder="请输入显示顺序" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</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>
</el-card>
</div>
</template>
<script>
import {
listCategory,
getCategory,
delCategory,
addCategory,
updateCategory
} from "@/api/iot/category";
export default {
name: "Category",
dicts: ["iot_yes_no"],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 产品分类表格数据
categoryList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
categoryName: null,
tenantName: null,
isSys: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
categoryName: [{
required: true,
message: "产品分类名称不能为空",
trigger: "blur"
}],
tenantId: [{
required: true,
message: "租户ID不能为空",
trigger: "blur"
}],
tenantName: [{
required: true,
message: "租户名称不能为空",
trigger: "blur"
}],
isSys: [{
required: true,
message: "是否系统通用不能为空",
trigger: "blur"
}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询产品分类列表 */
getList() {
this.loading = true;
listCategory(this.queryParams).then(response => {
this.categoryList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
categoryId: null,
categoryName: null,
tenantId: null,
tenantName: null,
isSys: null,
parentId: null,
orderNum: 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.categoryId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加产品分类";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const categoryId = row.categoryId || this.ids
getCategory(categoryId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改产品分类";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.categoryId != null) {
updateCategory(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addCategory(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const categoryIds = row.categoryId || this.ids;
let msg="";
this.$modal.confirm('是否确认删除产品分类编号为"' + categoryIds + '"的数据项?').then(function () {
return delCategory(categoryIds).then(response => {
msg=response.msg;
});
}).then(() => {
this.getList();
this.$modal.msgSuccess(msg);
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/category/export', {
...this.queryParams
}, `category_${new Date().getTime()}.xlsx`)
}
}
};
</script>

View File

@@ -0,0 +1,306 @@
<template>
<div style="padding: 6px">
<el-card v-show="showSearch" style="margin-bottom: 6px">
<div style="height:50px; color:#F56C6C;margin-left:20px;">该功能下个版本发布</div>
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="客户端ID" prop="clientId">
<el-input v-model="queryParams.clientId" placeholder="请输入客户端ID" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="授权平台" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择平台" clearable size="small">
<el-option v-for="dict in dict.type.oauth_platform" :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-card>
<el-card style="padding-bottom: 100px">
<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:clientDetails: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:clientDetails:edit']">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" disabled @click="handleDelete" v-hasPermi="['iot:clientDetails: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:clientDetails:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="clientDetailsList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="授权平台" align="center" prop="type">
<template slot-scope="scope">
<dict-tag :options="dict.type.oauth_platform" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="客户端ID" align="center" prop="clientId" />
<el-table-column label="资源" align="center" prop="resourceIds" />
<el-table-column label="权限范围" align="center" prop="scope" />
<el-table-column label="自动授权" align="center" prop="autoapprove">
<template slot-scope="scope">
<span v-if="scope.row.autoapprove=='true'">自动授权</span>
<span v-if="scope.row.autoapprove=='false'">用户验证</span>
</template>
</el-table-column>
<el-table-column label="授权模式" align="center" prop="authorizedGrantTypes">
<template slot-scope="scope">
<div v-html="formatGrantTypesDisplay(scope.row.authorizedGrantTypes)"></div>
</template>
</el-table-column>
<el-table-column label="回调地址" align="center" prop="webServerRedirectUri" min-width="130" />
<el-table-column label="权限" align="center" prop="authorities" />
<el-table-column label="Token有效期" align="center" prop="accessTokenValidity" />
<el-table-column label="Token刷新时间" align="center" prop="refreshTokenValidity" />
<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:clientDetails:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:clientDetails:remove']" disabled>删除</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="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item label="授权平台" prop="type">
<el-select v-model="form.type" placeholder="请选择授权平台">
<el-option v-for="dict in dict.type.oauth_platform" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
<el-form-item label="客户端ID" prop="clientId">
<el-input v-model="form.clientId" placeholder="请输入客户端ID" />
</el-form-item>
<el-form-item label="资源集合" prop="resourceIds">
<el-input v-model="form.resourceIds" placeholder="请输入资源" />
</el-form-item>
<el-form-item label="授权模式" prop="authorizedGrantTypes">
<el-input v-model="form.authorizedGrantTypes" type="textarea" placeholder="请输入授权模式" />
</el-form-item>
<el-form-item label="秘钥" prop="clientSecret">
<el-input v-model="form.clientSecret" placeholder="请输入客户端秘钥" />
</el-form-item>
<el-form-item label="回调地址" prop="webServerRedirectUri">
<el-input v-model="form.webServerRedirectUri" type="textarea" placeholder="请输入回调地址" />
</el-form-item>
<el-form-item label="权限" prop="authorities">
<el-input v-model="form.authorities" placeholder="请输入权限" />
</el-form-item>
<el-form-item label="Token有效期" prop="accessTokenValidity">
<el-input v-model="form.accessTokenValidity" placeholder="请输入Token有效时间" />
</el-form-item>
<el-form-item label="Token刷新时间" prop="refreshTokenValidity">
<el-input v-model="form.refreshTokenValidity" placeholder="请输入Token刷新有效时间" />
</el-form-item>
<el-form-item label="预留信息" prop="additionalInformation">
<el-input v-model="form.additionalInformation" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" disabled> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import {
listClientDetails,
getClientDetails,
delClientDetails,
addClientDetails,
updateClientDetails,
} from "@/api/iot/clientDetails";
export default {
name: "ClientDetails",
dicts: ["oauth_platform"],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 云云对接表格数据
clientDetailsList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
clientId: null,
authorizedGrantTypes: null,
autoapprove: null,
type: null,
},
// 表单参数
form: {},
// 表单校验
rules: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询云云对接列表 */
getList() {
this.loading = true;
listClientDetails(this.queryParams).then((response) => {
this.clientDetailsList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
clientId: null,
resourceIds: null,
clientSecret: null,
scope: null,
authorizedGrantTypes: null,
webServerRedirectUri: null,
authorities: null,
accessTokenValidity: null,
refreshTokenValidity: null,
additionalInformation: null,
autoapprove: null,
type: 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.clientId);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加云云对接";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const clientId = row.clientId || this.ids;
getClientDetails(clientId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改云云对接";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (this.form.clientId != null) {
updateClientDetails(this.form).then((response) => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addClientDetails(this.form).then((response) => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const clientIds = row.clientId || this.ids;
this.$modal
.confirm('是否确认删除云云对接编号为"' + clientIds + '"的数据项?')
.then(function () {
return delClientDetails(clientIds);
})
.then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download(
"iot/clientDetails/export", {
...this.queryParams,
},
`clientDetails_${new Date().getTime()}.xlsx`
);
},
/** 格式化显示授权模式 */
formatGrantTypesDisplay(data){
let dataArray=data.split(",");
let displayHtml=""
for(let i=0;i<dataArray.length;i++){
displayHtml=displayHtml+"<div style='background-color:#eee;margin:0 auto;margin-bottom:5px;width:86px;border-radius:5px;padding:3px;'>"+this.convertGrantType(dataArray[i])+"</div>"
}
return displayHtml;
},
/** 授权模式转换 */
convertGrantType(type){
if(type=="client_credentials"){
return "客户端模式"
}else if(type=="password"){
return "密码模式";
}else if(type=="authorization_code"){
return "授权码模式";
}else if(type=="implicit"){
return "简化模式";
}else if(type=="refresh_token"){
return "刷新Token";
}else{
return "";
}
}
},
};
</script>

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>

View File

@@ -0,0 +1,136 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="客户端" prop="categoryName">
<el-input v-model="queryParams.categoryName" placeholder="请输入客户端ID" 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-card>
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="clientList">
<el-table-column label="客户端ID" align="left" header-align="center" prop="clientid">
<template slot-scope="scope">
<el-link :underline="false" type="primary">{{scope.row.clientid}}</el-link>
</template>
</el-table-column>
<el-table-column label="节点" align="center" prop="node" width="120" />
<el-table-column label="IP地址" align="center" prop="ip_address" />
<el-table-column label="类型" align="center" prop="type">
<template slot-scope="scope">
<el-tag type="danger" v-if="scope.row.clientid.indexOf('server')==0">服务端</el-tag>
<el-tag type="success" v-else-if="scope.row.clientid.indexOf('web')==0">Web端</el-tag>
<el-tag type="warning" v-else-if="scope.row.clientid.indexOf('phone')==0">移动端</el-tag>
<el-tag type="info" v-else-if="scope.row.clientid.indexOf('test')==0">测试端</el-tag>
<el-tag type="primary" v-else>设备端</el-tag>
</template>
</el-table-column>
<el-table-column label="连接状态" align="center" prop="connected">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.connected">已连接</el-tag>
<el-tag type="info" v-else>已断开</el-tag>
</template>
</el-table-column>
<el-table-column label="心跳(秒)" align="center" prop="keepalive" width="100" />
<el-table-column label="会话过期间隔" align="center" prop="expiry_interval" width="100" />
<el-table-column label="当前订阅数量" align="center" prop="subscriptions_cnt" width="100" />
<el-table-column label="连接时间" align="center" prop="connected_at" />
<el-table-column label="会话创建时间" align="center" prop="created_at" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="small" type="danger" v-if="scope.row.connected" style="padding:5px;" v-hasPermi="['monitor:online:edit']">
<svg-icon icon-class="disconnect" /> 断开连接
</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams._page" :limit.sync="queryParams._limit" @pagination="getList" />
<!-- 添加或修改产品分类对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import {
listMqttClient
} from "@/api/iot/emqx"
export default {
name: "Category",
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 产品分类表格数据
clientList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
_limit: 10,
_page: 1,
},
// 表单参数
form: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询客户端列表 */
getList() {
this.loading = true;
listMqttClient(this.queryParams).then(response => {
this.clientList = response.data.data;
this.total = response.data.meta.count;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
}
};
</script>

View File

@@ -0,0 +1,80 @@
<template>
<div style="padding:6px;">
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="listenerList">
<el-table-column label="协议" align="center" prop="protocol" />
<el-table-column label="监听地址" align="center" prop="listen_on" />
<el-table-column label="最大连接数" align="center" prop="max_conns" />
<el-table-column label="当前连接数" align="center" prop="current_conns"/>
<el-table-column label="连接成功数" align="center" prop="acceptors" />
<el-table-column label="账号错误数" align="center" prop="shutdown_count.bad_username_or_password" />
<el-table-column label="功能错误数" align="center" prop="shutdown_count.function_clause" />
<el-table-column label="SSL关闭数" align="center" prop="shutdown_count.ssl_closed" />
</el-table>
<!-- 添加或修改产品分类对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import{listMqttListener} from "@/api/iot/emqx"
export default {
name: "Category",
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 列表
listenerList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 表单参数
form: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询客户端列表 */
getList() {
this.loading = true;
listMqttListener().then(response => {
this.listenerList=response.data.data[0].listeners;
console.log(response);
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
}
};
</script>

View File

@@ -0,0 +1,133 @@
<template>
<div style="padding:6px;">
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="pluginList">
<el-table-column label="插件名称" align="center" prop="name" width="300" />
<el-table-column label="版本" align="center" prop="version" width="100" />
<el-table-column label="类型" align="center" prop="type" width="120" />
<el-table-column label="状态" align="center" prop="active" width="150">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.active">运行中</el-tag>
<el-tag type="info" v-else>已停止</el-tag>
</template>
</el-table-column>
<el-table-column label="描述" align="left" prop="description" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="small" type="success" style="padding:5px;" @click="loadMqttPlugin(scope.row.name)" v-if="!scope.row.active" v-hasPermi="['monitor:online:edit']">
<svg-icon icon-class="start" /> 启动
</el-button>
<el-button size="small" type="danger" style="padding:5px;" @click="unloadMqttPlugin(scope.row.name)" v-else v-hasPermi="['monitor:online:edit']">
<svg-icon icon-class="stop" /> 停止
</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" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import {
listMqttPlugin,
loadMqttPlugin,
unloadMqttPlugin
} from "@/api/iot/emqx"
export default {
name: "Category",
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 列表
pluginList: [],
// 节点名称
node: "",
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 表单参数
form: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询客户端列表 */
getList() {
this.loading = true;
listMqttPlugin().then(response => {
this.pluginList = response.data.data[0].plugins;
this.node = response.data.data[0].node;
this.loading = false;
});
},
/** 启用插件*/
loadMqttPlugin(plugin) {
this.$confirm('是否启用插件:' + plugin + ' ?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
loadMqttPlugin(this.node, plugin).then(response => {
if (response.data.code == 0) {
this.getList();
this.$message({
type: 'success',
message: '成功启用插件!'
});
}
})
}).catch(() => {});
},
/** 卸载插件*/
unloadMqttPlugin(plugin) {
this.$confirm('是否停止插件:' + plugin + ' ?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
unloadMqttPlugin(this.node, plugin).then(response => {
if (response.data.code == 0) {
this.getList();
this.$message({
type: 'success',
message: '成功停止插件!'
});
}
})
}).catch(() => {});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
}
};
</script>

View File

@@ -0,0 +1,123 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="客户端" prop="categoryName">
<el-input v-model="queryParams.categoryName" placeholder="请输入客户端ID" 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-card>
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="subscribeList">
<el-table-column label="类型" align="center" prop="type" width="150">
<template slot-scope="scope">
<el-tag type="danger" v-if="scope.row.clientid.indexOf('server')==0">服务端</el-tag>
<el-tag type="success" v-else-if="scope.row.clientid.indexOf('web')==0">Web端</el-tag>
<el-tag type="warning" v-else-if="scope.row.clientid.indexOf('phone')==0">移动端</el-tag>
<el-tag type="info" v-else-if="scope.row.clientid.indexOf('test')==0">测试端</el-tag>
<el-tag type="primary" v-else>设备端</el-tag>
</template>
</el-table-column>
<el-table-column label="主题" align="left" header-align="center" prop="topic">
<template slot-scope="scope">
<span style="font-weight:bold">{{scope.row.topic}}</span>
</template>
</el-table-column>
<el-table-column label="客户端ID" align="center" header-align="center" prop="clientid">
<template slot-scope="scope">
<el-link :underline="false">{{scope.row.clientid}}</el-link>
</template>
</el-table-column>
<el-table-column label="Qos" align="center" prop="qos" width="100" />
<el-table-column label="节点" align="center" prop="node" />
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams._page" :limit.sync="queryParams._limit" @pagination="getList" />
<!-- 添加或修改产品分类对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import {
listMqttSubscribe
} from "@/api/iot/emqx"
export default {
name: "Category",
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 列表
subscribeList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
_limit: 10,
_page: 1,
},
// 表单参数
form: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询客户端列表 */
getList() {
this.loading = true;
listMqttSubscribe(this.queryParams).then(response => {
this.subscribeList = response.data.data;
this.total = response.data.meta.count;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
}
};
</script>

View File

@@ -0,0 +1,103 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="主题" prop="categoryName">
<el-input v-model="queryParams.categoryName" 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-card>
<el-card style="padding-bottom:100px;">
<el-table v-loading="loading" :data="topicList">
<el-table-column label="节点" align="center" prop="node" width="300"/>
<el-table-column label="主题" align="left" prop="topic" />
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams._page" :limit.sync="queryParams._limit" @pagination="getList" />
<!-- 添加或修改产品分类对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="分类名称" prop="categoryName">
<el-input v-model="form.categoryName" placeholder="请输入产品分类名称" />
</el-form-item>
<el-form-item label="显示顺序" prop="orderNum">
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import{listMqttTopic} from "@/api/iot/emqx"
export default {
name: "Category",
data() {
return {
// 遮罩层
loading: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 列表
topicList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
_limit: 10,
_page: 1,
},
// 表单参数
form: {},
};
},
created() {
this.getList();
},
methods: {
/** 查询客户端列表 */
getList() {
this.loading = true;
listMqttTopic(this.queryParams).then(response => {
this.topicList=response.data.data;
this.total=response.data.meta.count;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
}
};
</script>

View File

@@ -0,0 +1,374 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="固件名称" prop="firmwareName">
<el-input v-model="queryParams.firmwareName" 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>
<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-card>
<el-card style="padding-bottom:100px;">
<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:firmware: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:firmware: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:firmware: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:firmware:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="firmwareList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="固件名称" align="center" prop="firmwareName" />
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="租户名称" align="center" prop="tenantName" />
<el-table-column label="系统定义" align="center" prop="isSys">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isSys" />
</template>
</el-table-column>
<el-table-column label="固件版本" align="center" prop="version">
<template slot-scope="scope">
<span>Version </span> {{scope.row.version}}
</template>
</el-table-column>
<el-table-column label="路径" align="left" prop="filePath" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
<template slot-scope="scope">
<el-button size="small" type="info" style="padding:5px;" icon="el-icon-download" @click="handleDownload(scope.row)">下载</el-button>
<el-button size="small" type="primary" style="padding:5px;" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:firmware:edit']">修改</el-button>
<el-button size="small" type="danger" style="padding:5px;" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:firmware:remove']">删除</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="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="固件名称" prop="firmwareName">
<el-input v-model="form.firmwareName" placeholder="请输入固件名称" />
</el-form-item>
<el-form-item label="所属产品" prop="productId">
<el-select v-model="form.productId" placeholder="请选择产品" @change="selectProduct">
<el-option v-for="product in productShortList" :key="product.id" :label="product.name" :value="product.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="固件版本" prop="version">
<el-input v-model="form.version" placeholder="请输入固件版本" type="number" />
</el-form-item>
<el-form-item label="固件上传" prop="filePath">
<fileUpload ref="file-upload" :value="form.filePath" :limit="1" :fileSize="10" :fileType='["bin", "zip", "pdf"]' @input="getFilePath($event)"></fileUpload>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</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>
</el-card>
</div>
</template>
<script>
import {
download
} from '@/api/iot/tool'
import fileUpload from '../../../components/FileUpload/index'
import {
listShortProduct
} from "@/api/iot/product"
import {
listFirmware,
getFirmware,
delFirmware,
addFirmware,
updateFirmware
} from "@/api/iot/firmware";
import {
getToken
} from "@/utils/auth";
export default {
name: "Firmware",
dicts: ["iot_yes_no"],
components: {
fileUpload
},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 产品固件表格数据
firmwareList: [],
// 产品简短列表
productShortList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
firmwareName: null,
productName: null,
tenantName: null,
isSys: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
firmwareName: [{
required: true,
message: "固件名称不能为空",
trigger: "blur"
}],
productId: [{
required: true,
message: "产品ID不能为空",
trigger: "blur"
}],
productName: [{
required: true,
message: "产品名称不能为空",
trigger: "blur"
}],
tenantId: [{
required: true,
message: "租户ID不能为空",
trigger: "blur"
}],
tenantName: [{
required: true,
message: "租户名称不能为空",
trigger: "blur"
}],
isSys: [{
required: true,
message: "是否系统通用不能为空",
trigger: "blur"
}],
version: [{
required: true,
message: "固件版本不能为空",
trigger: "blur"
}],
filePath: [{
required: true,
message: "文件路径不能为空",
trigger: "blur"
}],
},
// 上传参数
upload: {
// 是否禁用上传
isUploading: false,
// 设置上传的请求头部
headers: {
Authorization: "Bearer " + getToken()
},
// 上传的地址
url: process.env.VUE_APP_BASE_API + "/iot/tool/upload",
// 上传的文件列表
fileList: []
},
};
},
created() {
this.getList();
this.getProductShortList();
},
methods: {
/** 查询产品固件列表 */
getList() {
this.loading = true;
listFirmware(this.queryParams).then(response => {
this.firmwareList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 查询产品简短列表 */
getProductShortList() {
listShortProduct().then(response => {
this.productShortList = response.data;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
firmwareId: null,
firmwareName: null,
productId: null,
productName: null,
tenantId: null,
tenantName: null,
isSys: null,
version: null,
filePath: 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.firmwareId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加产品固件";
this.upload.fileList = [];
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const firmwareId = row.firmwareId || this.ids
getFirmware(firmwareId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改产品固件";
this.upload.fileList = [{
name: this.form.firmwareName,
url: this.form.filePath
}];
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.firmwareId != null) {
updateFirmware(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addFirmware(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const firmwareIds = row.firmwareId || this.ids;
this.$modal.confirm('是否确认删除产品固件编号为"' + firmwareIds + '"的数据项?').then(function () {
return delFirmware(firmwareIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/firmware/export', {
...this.queryParams
}, `firmware_${new Date().getTime()}.xlsx`)
},
/** 选择产品 */
selectProduct(val) {
for (var i = 0; i < this.productShortList.length; i++) {
if (this.productShortList[i].id == val) {
this.form.productName = this.productShortList[i].name;
return;
}
}
},
// 获取文件路径
getFilePath(data){
console.log(data);
this.form.filePath=data;
},
// 文件提交处理
submitUpload() {
this.$refs.upload.submit();
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.isUploading = false;
this.form.filePath = response.url;
this.$modal.msgSuccess(response.msg);
},
// 文件下载处理
handleDownload(row) {
download(row.filePath);
}
},
};
</script>

View File

@@ -0,0 +1,147 @@
<template>
<div style="padding:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<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>
<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="deviceList" @select="handleSelectionChange" ref="multipleTable" size="mini" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="设备名称" align="center" prop="deviceName" />
<el-table-column label="设备编号" align="center" prop="serialNumber" />
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="设备状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_device_status" :value="scope.row.status" />
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
</div>
</template>
<script>
import {
getDeviceIds
} from "@/api/iot/group"
import {
listDeviceShort,
} from "@/api/iot/device";
export default {
name: "device-list",
dicts: ['iot_device_status'],
props: {
groupId: {
type: Number,
default: null
}
},
data() {
return {
// 遮罩层
loading: true,
// 分组信息
parentGroupId:0,
// 选中数组
ids: [],
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备表格数据
deviceList: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
deviceName: null,
productId: null,
productName: null,
userId: null,
userName: null,
tenantId: null,
tenantName: null,
serialNumber: null,
status: null,
networkAddress: null,
activeTime: null,
},
};
},
watch: {
// 获取到父组件传递的group后刷新列表
groupId: {
handler(newVal, oldVal) {
this.parentGroupId = newVal;
// 获取分组下的设备
this.queryParams.pageNum=1;
this.getDeviceIdsByGroupId();
},
immediate: true
}
},
created() {
},
methods: {
// 获取分组下关联的设备ID数组
getDeviceIdsByGroupId() {
getDeviceIds(this.parentGroupId).then(response => {
this.ids = response.data;
this.getList();
});
},
/** 查询设备列表 */
getList() {
this.loading = true;
this.queryParams.params = {};
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.loading = false;
// 设置分组关联的设备选中
this.deviceList.forEach(row => {
this.$nextTick(() => {
if (this.ids.some(x => x === row.deviceId)) {
this.$refs.multipleTable.toggleRowSelection(row, true);
}
})
});
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeActiveTime = [];
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.deviceId)
console.log("选择赋值");
console.log(this.ids);
this.single = selection.length !== 1
this.multiple = !selection.length
// Id数组传递到父组件
this.$emit('idsToParentEvent', this.ids)
},
}
};
</script>

View File

@@ -0,0 +1,281 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="分组名称" prop="groupName">
<el-input v-model="queryParams.groupName" 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-card>
<el-card style="padding-bottom:100px;">
<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:group: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:group: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:group: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:group:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="groupList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="分组名称" align="center" prop="groupName" width="200" />
<el-table-column label="分组排序" align="center" prop="groupOrder" width="100" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<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" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="230">
<template slot-scope="scope">
<el-button size="small" type="success" style="padding:5px;" icon="el-icon-edit" @click="selectDevice(scope.row)" v-hasPermi="['iot:group:edit']">添加设备</el-button>
<el-button size="small" type="primary" style="padding:5px;" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:group:edit']">修改</el-button>
<el-button size="small" type="danger" style="padding:5px;" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:group:remove']">删除</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="选择设备" :visible.sync="openDeviceList" width="800px" append-to-body>
<device-list ref="deviceList" :groupId="deviceGroup.groupId" @idsToParentEvent="getChildData($event)"></device-list>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleDeviceSelected"> </el-button>
<el-button @click="closeSelectDeviceList"> </el-button>
</div>
</el-dialog>
<!-- 添加或修改设备分组对话框 -->
<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="groupName">
<el-input v-model="form.groupName" placeholder="请输入分组名称" />
</el-form-item>
<el-form-item label="分组排序" prop="groupOrder">
<el-input v-model="form.groupOrder" type="number" placeholder="请输入分组排序" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</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>
</el-card>
</div>
</template>
<script>
import deviceList from "./device-list"
import {
listGroup,
getGroup,
delGroup,
addGroup,
updateGroup,
updateDeviceGroups
} from "@/api/iot/group";
export default {
name: "Group",
components: {
deviceList
},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备分组表格数据
groupList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 是否显示设备列表
openDeviceList: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
groupName: null,
userName: null,
},
// 设备分组
deviceGroup: {},
// 表单参数
form: {},
// 表单校验
rules: {
groupName: [{
required: true,
message: "分组名称不能为空",
trigger: "blur"
}],
groupOrder: [{
required: true,
message: "分组排序不能为空,最大值为99",
trigger: "blur"
},
{
min: 1,
max: 2,
message: '范围在 0 到 99',
trigger: 'blur'
}
],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询设备分组列表 */
getList() {
this.loading = true;
listGroup(this.queryParams).then(response => {
this.groupList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 关闭选择设备列表
closeSelectDeviceList() {
this.openDeviceList = false;
},
// 表单重置
reset() {
this.form = {
groupId: null,
groupName: null,
groupOrder: null,
userId: null,
userName: 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.groupId)
console.log(this.ids);
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加设备分组";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const groupId = row.groupId || this.ids
getGroup(groupId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改设备分组";
});
},
/** 选择设备 */
selectDevice(row) {
this.deviceGroup.groupId = row.groupId;
this.openDeviceList = true;
this.$refs.deviceList.getDeviceIdsByGroupId();
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.groupId != null) {
updateGroup(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addGroup(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const groupIds = row.groupId || this.ids;
this.$modal.confirm('是否确认删除设备分组编号为"' + groupIds + '"的数据项?').then(function () {
return delGroup(groupIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/group/export', {
...this.queryParams
}, `group_${new Date().getTime()}.xlsx`)
},
// 获取子组件选中的ID数组
getChildData(data) {
this.deviceGroup.deviceIds = data;
},
// 更新分组下的设备
handleDeviceSelected() {
updateDeviceGroups(this.deviceGroup).then(response => {
this.$modal.msgSuccess("更新分组下的设备成功");
this.openDeviceList = false;
})
}
}
};
</script>

View File

@@ -0,0 +1,391 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="日志名称" prop="logName">
<el-input v-model="queryParams.logName" placeholder="请输入日志名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<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_things_type" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="日志级别" prop="logLevel">
<el-input v-model="queryParams.logLevel" placeholder="请输入日志级别" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="设备ID" prop="deviceId">
<el-input v-model="queryParams.deviceId" placeholder="请输入设备ID" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<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="userName">
<el-input v-model="queryParams.userName" placeholder="请输入用户昵称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="租户名称" prop="tenantName">
<el-input v-model="queryParams.tenantName" placeholder="请输入租户名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="生成告警" prop="isAlert">
<el-input v-model="queryParams.isAlert" 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_yes_no" :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-card>
<el-card style="padding-bottom:100px;">
<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:log: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:log: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:log: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:log:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="日志名称" align="center" prop="logName" />
<el-table-column label="值" align="center" prop="logValue" />
<el-table-column label="类型" align="center" prop="logType">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_things_type" :value="scope.row.logType" />
</template>
</el-table-column>
<el-table-column label="日志级别" align="center" prop="logLevel">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.logLevel" />
</template>
</el-table-column>
<el-table-column label="设备ID" align="center" prop="deviceId" />
<el-table-column label="设备名称" align="center" prop="deviceName" />
<el-table-column label="用户ID" align="center" prop="userId" />
<el-table-column label="用户昵称" align="center" prop="userName" />
<el-table-column label="租户ID" align="center" prop="tenantId" />
<el-table-column label="租户名称" align="center" prop="tenantName" />
<el-table-column label="触发源" align="center" prop="triggerSource">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.triggerSource" />
</template>
</el-table-column>
<el-table-column label="生成告警" align="center" prop="isAlert">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isAlert" />
</template>
</el-table-column>
<el-table-column label="告警处理" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="small" type="primary" style="padding:5px;" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:log:edit']">处理</el-button>
<!-- <el-button size="small" type="danger" style="padding:5px;" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:log:remove']">删除</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="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="日志名称" prop="logName">
<el-input v-model="form.logName" placeholder="请输入日志名称" />
</el-form-item>
<el-form-item label="类型" prop="logType">
<el-select v-model="form.logType" placeholder="请选择类型">
<el-option v-for="dict in dict.type.iot_things_type" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
<el-form-item label="日志级别" prop="logLevel">
<el-input v-model="form.logLevel" placeholder="请输入日志级别" />
</el-form-item>
<el-form-item label="设备ID" prop="deviceId">
<el-input v-model="form.deviceId" placeholder="请输入设备ID" />
</el-form-item>
<el-form-item label="设备名称" prop="deviceName">
<el-input v-model="form.deviceName" placeholder="请输入设备名称" />
</el-form-item>
<el-form-item label="用户ID" prop="userId">
<el-input v-model="form.userId" placeholder="请输入用户ID" />
</el-form-item>
<el-form-item label="用户昵称" prop="userName">
<el-input v-model="form.userName" placeholder="请输入用户昵称" />
</el-form-item>
<el-form-item label="租户ID" prop="tenantId">
<el-input v-model="form.tenantId" placeholder="请输入租户ID" />
</el-form-item>
<el-form-item label="租户名称" prop="tenantName">
<el-input v-model="form.tenantName" placeholder="请输入租户名称" />
</el-form-item>
<el-form-item label="触发源" prop="triggerSource">
<el-input v-model="form.triggerSource" placeholder="请输入触发源" />
</el-form-item>
<el-form-item label="是否生成告警" prop="isAlert">
<el-input v-model="form.isAlert" placeholder="请输入是否生成告警" />
</el-form-item>
<el-form-item label="告警处理">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in dict.type.iot_yes_no" :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
<el-form-item label="日志收到的值" prop="logValue">
<el-input v-model="form.logValue" placeholder="请输入日志收到的值" />
</el-form-item>
<el-form-item label="是否置顶" prop="istop">
<el-input v-model="form.istop" placeholder="请输入是否置顶" />
</el-form-item>
<el-form-item label="是否监测" prop="ismonitor">
<el-input v-model="form.ismonitor" placeholder="请输入是否监测" />
</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>
</el-card>
</div>
</template>
<script>
import {
listLog,
getLog,
delLog,
addLog,
updateLog
} from "@/api/iot/log";
export default {
name: "Log",
dicts: ['iot_things_type', 'iot_yes_no'],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备日志表格数据
logList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
logName: null,
logType: null,
logLevel: null,
deviceId: null,
deviceName: null,
userName: null,
tenantName: null,
triggerSource: null,
isAlert: null,
status: null,
istop: null,
ismonitor: null
},
// 表单参数
form: {},
// 表单校验
rules: {
logName: [{
required: true,
message: "日志名称不能为空",
trigger: "blur"
}],
logType: [{
required: true,
message: "类型不能为空",
trigger: "change"
}],
logLevel: [{
required: true,
message: "日志级别不能为空",
trigger: "blur"
}],
deviceId: [{
required: true,
message: "设备ID不能为空",
trigger: "blur"
}],
deviceName: [{
required: true,
message: "设备名称不能为空",
trigger: "blur"
}],
userId: [{
required: true,
message: "用户ID不能为空",
trigger: "blur"
}],
userName: [{
required: true,
message: "用户昵称不能为空",
trigger: "blur"
}],
tenantId: [{
required: true,
message: "租户ID不能为空",
trigger: "blur"
}],
tenantName: [{
required: true,
message: "租户名称不能为空",
trigger: "blur"
}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询设备日志列表 */
getList() {
this.loading = true;
listLog(this.queryParams).then(response => {
this.logList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
deviceLogId: null,
logName: null,
logType: null,
logLevel: null,
deviceId: null,
deviceName: null,
userId: null,
userName: null,
tenantId: null,
tenantName: null,
triggerSource: null,
isAlert: null,
status: 0,
createBy: null,
createTime: null,
remark: null,
logValue: null,
istop: null,
ismonitor: 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.deviceLogId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加设备日志";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const deviceLogId = row.deviceLogId || this.ids
getLog(deviceLogId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改设备日志";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.deviceLogId != null) {
updateLog(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addLog(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const deviceLogIds = row.deviceLogId || this.ids;
this.$modal.confirm('是否确认删除设备日志编号为"' + deviceLogIds + '"的数据项?').then(function () {
return delLog(deviceLogIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/log/export', {
...this.queryParams
}, `log_${new Date().getTime()}.xlsx`)
}
}
};
</script>

18
vue/src/views/iot/map.js Normal file
View File

@@ -0,0 +1,18 @@
export function loadBMap() {
let baiduAK="nAtaBg9FYzav6c8P9rF9qzsWZfT8O0PD";
return new Promise(function(resolve, reject) {
if (typeof BMap !== 'undefined') {
resolve(BMap)
return true
}
window.onBMapCallback = function() {
resolve(BMap)
}
let script = document.createElement('script')
script.type = 'text/javascript'
script.src =
'http://api.map.baidu.com/api?v=2.0&ak='+ baiduAK +'&__ec_v__=20190126&callback=onBMapCallback'
script.onerror = reject
document.head.appendChild(script)
})
}

View File

@@ -0,0 +1,256 @@
<template>
<div style="padding:6px;">
<el-card style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<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="categoryName">
<el-input v-model="queryParams.categoryName" 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_product_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-item style="float:right;">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleEditProduct(0)" v-hasPermi="['iot:product: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 productList" :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="handleEditProduct(item)" style="font-weight:bold;font-size:16px;line-height:32px;">
<svg-icon icon-class="product" /> {{item.productName}}
<el-tag type="info" size="mini" style="margin-left:5px;font-weight:200" v-if="item.isSys==1">系统</el-tag>
</el-link>
</el-col>
<el-col :span="4">
<el-tooltip class="item" effect="dark" content="取消发布" placement="top-start" v-if="item.status==2">
<el-button type="success" size="mini" style="padding:5px;" @click="changeProductStatus(item.productId,1)">已发布</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="现在发布" placement="top-start" v-if="item.status==1">
<el-button type="info" size="mini" style="padding:5px;" @click="changeProductStatus(item.productId,2)">未发布</el-button>
</el-tooltip>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="14">
<el-descriptions :column="1" size="small" style="margin-top:10px;">
<el-descriptions-item label="所属分类">
<el-link type="primary" :underline="false">{{item.categoryName}}</el-link>
</el-descriptions-item>
<el-descriptions-item label="产品类型">
<dict-tag :options="dict.type.iot_device_type" :value="item.deviceType" />
</el-descriptions-item>
<el-descriptions-item label="联网方式">
<dict-tag :options="dict.type.iot_network_method" :value="item.networkMethod" />
</el-descriptions-item>
<el-descriptions-item label="创建时间">
<span>{{ parseTime(item.createTime, '{y}-{m}-{d}') }}</span>
</el-descriptions-item>
</el-descriptions>
</el-col>
<el-col :span="10">
<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-button-group style="margin-top:15px;">
<el-button size="mini" type="primary" icon="el-icon-edit" @click="handleEditProduct(item)" v-hasPermi="['iot:product:edit']">详情</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(item)" v-hasPermi="['iot:product:remove']" v-if="item.status==1">删除</el-button>
<el-button size="mini" type="info" icon="el-icon-download" @click="handleGeneratorSDK(item)" v-hasPermi="['iot:product:edit']" v-if="item.status==2">下载SDK</el-button>
<el-button size="mini" type="warning" icon="el-icon-search" @click="handleViewDevice(item.productId)" v-hasPermi="['tool:gen:edit']">查看设备</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" />
<!-- 下载SDK -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-link type="danger" style="padding-left:10px;" :underline="false">该功能暂未实现参考教程和项目的SDK示例</el-link>
<el-form label-width="80px">
<el-form-item label="选择设备">
<el-radio-group v-model="form.datatype">
<el-radio v-for="dict in dict.type.iot_device_chip" :key="dict.value" :label="dict.value" style="margin-top:15px;width:160px;">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="downloadSdk" disabled> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-card>
</div>
</template>
<script>
import {
listProduct,
delProduct,
changeProductStatus
} from "@/api/iot/product";
export default {
name: "Product",
dicts: ['iot_yes_no', 'iot_product_status', 'iot_device_type', 'iot_network_method', 'iot_vertificate_method', 'iot_device_chip'],
data() {
return {
// 遮罩层
loading: true,
// 总条数
total: 0,
// 产品表格数据
productList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
productName: null,
categoryId: null,
categoryName: null,
tenantId: null,
tenantName: null,
isSys: null,
status: null,
deviceType: null,
networkMethod: null,
},
// 表单参数
form: {},
baseUrl: process.env.VUE_APP_BASE_API,
};
},
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);
this.getList();
}
},
methods: {
/** 查询产品列表 */
getList() {
this.loading = true;
listProduct(this.queryParams).then(response => {
this.productList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 更新产品状态 */
changeProductStatus(productId,status) {
let message="发生错误了";
if(status==2){
message="产品发布后不能再更改产品内容和对应物模型 ";
}else if(status==1){
message="产品下不能有已经创建的设备,才能取消发布哦 "
}
this.$confirm(message, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let data = {};
data.productId = productId;
data.status = status;
changeProductStatus(data).then(response => {
this.getList();
this.$modal.alertSuccess(response.msg);
}).catch(() => {});
}).catch(() => {});
},
/** 修改按钮操作 */
handleViewDevice(productId) {
this.$router.push({
path: '/iot/device',
query: {
t: Date.now(),
productId: productId,
}
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 生成SDK */
handleGeneratorSDK(row) {
this.title = "生成SDK"
this.open = true;
},
/** 下载SDK */
downloadSdk() {
this.$download.zip("/iot/tool/genSdk?deviceChip=" + 1, "wumeismart-sdk");
},
/** 删除按钮操作 */
handleDelete(row) {
const productIds = row.productId || this.ids;
let msg = "";
this.$modal.confirm('是否确认删除产品编号为"' + productIds + '"的数据项?').then(function () {
return delProduct(productIds).then(response => {
msg = response.msg;
});
}).then(() => {
this.getList();
this.$modal.msgSuccess(msg);
}).catch(() => {});
},
/** 修改按钮操作 */
handleEditProduct(row) {
let productId = 0;
if (row != 0) {
productId = row.productId || this.ids
}
this.$router.push({
path: '/iot/product-edit',
query: {
productId: productId,
pageNum: this.queryParams.pageNum
}
});
},
}
};
</script>

View File

@@ -0,0 +1,670 @@
<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="alertName">
<el-input v-model="queryParams.alertName" placeholder="请输入告警名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="告警级别" prop="alertLevel">
<el-select v-model="queryParams.alertLevel" placeholder="请选择告警级别" clearable size="small">
<el-option v-for="dict in dict.type.iot_alert_level" :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-item>
<el-link type="danger" style="padding-top:5px" :underline="false">该功能未完成</el-link>
</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:alert: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:alert: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:alert: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:alert:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="alertList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="告警ID" align="center" prop="alertId" />
<el-table-column label="告警名称" align="center" prop="alertName" />
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<el-tag type="success" v-if="scope.row.status==1">启动</el-tag>
<el-tag type="danger" v-if="scope.row.status==2">暂停</el-tag>
</template>
</el-table-column>
<el-table-column label="告警级别" align="center" prop="alertLevel">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_alert_level" :value="scope.row.alertLevel" />
</template>
</el-table-column>
<el-table-column label="产品ID" align="center" prop="productId" />
<el-table-column label="产品名称" align="center" prop="productName" />
<el-table-column label="触发器" align="center" prop="triggers" />
<el-table-column label="执行动作" align="center" prop="actions" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<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:alert:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:alert:remove']">删除</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="80px">
<el-row>
<el-col :span="15">
<el-form-item label="告警名称" prop="alertName">
<el-input v-model="form.alertName" placeholder="请输入告警名称" />
</el-form-item>
</el-col>
<el-col :span="20">
<el-form-item label="告警级别" prop="alertLevel">
<el-select v-model="form.alertLevel" placeholder="请选择告警级别">
<el-option v-for="dict in dict.type.iot_alert_level" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="21">
<el-form-item label="告警状态">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in alertType" :key="dict.value" :label="dict.value">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="触发器" prop="griggers">
<el-select v-model="form.condition" placeholder="请选择" size="small" style="margin-bottom:10px;">
<el-option v-for="item in triggerConditions" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
<div v-for="(item,index) in form.triggers" :key="index" style="margin-bottom:15px;border:1px solid #ddd;padding:10px;">
<el-row>
<el-col :span="4">
<el-select v-model="item.source" placeholder="请选择" size="small" @change="changeTriggerSource">
<el-option v-for="subItem in triggerSource" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="16" :offset="1" v-if="item.source==2">
<el-time-picker v-model="timerTimeValue" size="small" value-format="HH:mm" placeholder="选择执行时间" @change="timeChange" :disabled="item.isAdvance==1"></el-time-picker>
</el-col>
<el-col :span="2" :offset="item.source==1?17:1" v-if="index!=0"><a style="color:#F56C6C" @click="removeTriggerItem(index)">删除</a></el-col>
</el-row>
<!--定时-->
<el-row v-if="item.source==2">
<el-col :span="24">
<el-row style="margin-bottom:5px;">
<el-col :span="4">
<el-select v-model="timerWeekRepeatValue" placeholder="请选择" @change="repeatChange" size="small" :disabled="item.isAdvance==1">
<el-option v-for="item in timerWeekRepeats" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-col>
<el-col :span="15" :offset="1" v-if="timerWeekRepeatValue==3">
<el-select v-model="timerWeekValue" placeholder="请选择" multiple style="width:485px" @change="weekChange" size="small" :disabled="item.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-col>
<el-col :span="24">
<el-row>
<el-col :span="18">
<el-input v-model="item.cronExpression" placeholder="cron执行表达式" :disabled="item.isAdvance==0" size="small">
<template slot="append">
<el-button type="primary" @click="handleShowCron(item,index)" :disabled="item.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="item.isAdvance" :true-label="1" :false-label="0" @change="customerCronChange">自定义表达式</el-checkbox>
</el-col>
</el-row>
</el-col>
</el-row>
<!--设备-->
<el-row>
<el-col :span="4">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="4" :offset="1">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="5" :offset="1">
<el-select v-model="item.operator" placeholder="请选择操作符" size="small">
<el-option key="=" label="等于(=)" value="=" />
<el-option key="!=" label="不等于(!=)" value="!=" />
<el-option key=">" label="大于(>)" value=">" />
<el-option key="<" label="小于(<)" value="<" />
<el-option key=">=" label="大于等于(>=)" value=">=" />
<el-option key="<=" label="小于等于(<=)" value="<=" />
<el-option key="contain" label="包含(contain)" value="contain" />
<el-option key="notcontain" label="不包含(not contain)" value="notcontain" />
</el-select>
</el-col>
<el-col :span="5" :offset="1">
<el-input v-model="item.value" placeholder="值" size="small" />
</el-col>
</el-row>
</div>
<div>+ <a style="color:#409EFF" @click="addTriggerItem()">添加触发器</a></div>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="执行动作">
<el-row v-for="(item,index) in form.actions" :key="index" style="margin-bottom:10px;">
<el-col :span="4">
<el-select v-model="item.modelType" placeholder="请选择">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="4" :offset="1">
<el-select v-model="item.modelType" placeholder="请选择">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="11" :offset="1">
<el-input v-model="item.value" placeholder="值" />
</el-col>
<el-col :span="2" :offset="1" v-if="index!=0"><a style="color:#F56C6C" @click="removeActionItem(index)">删除</a></el-col>
</el-row>
<div>+ <a style="color:#409EFF" @click="addActionItem()">添加执行动作</a></div>
</el-form-item>
</el-col>
</el-row>
<el-col :span="16">
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-col>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" disabled> </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>
</div>
</template>
<script>
import {
listAlert,
getAlert,
delAlert,
addAlert,
updateAlert
} from "@/api/iot/alert";
import {
cacheJsonThingsModel
} from "@/api/iot/model";
import Crontab from '@/components/Crontab'
export default {
name: "device-alert",
dicts: ['iot_alert_level', 'sys_job_status'],
components: {
Crontab
},
props: {
product: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的productId后刷新列表
product: function (newVal, oldVal) {
this.productInfo = newVal;
if (this.productInfo && this.productInfo.productId != 0) {
this.queryParams.productId = this.productInfo.productId;
this.getList();
// 获取缓存的Json物模型
cacheJsonThingsModel(newVal.productId).then(response => {
this.thingsModel = JSON.parse(response.data);
});
}
}
},
data() {
return {
// 物模型JSON
thingsModel: {},
// 遮罩层
loading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 设备告警表格数据
alertList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 是否显示Cron表达式弹出层
openCron: false,
// 传入的表达式
expression: "",
// 触发器的索引,用于接收传入的表达式
triggerIndex: 0,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
alertName: null,
alertLevel: null,
productId: null,
productName: null,
},
// 周
timerWeekRepeats: [{
value: '1',
label: '每天'
}, {
value: '2',
label: '仅此一次'
}, {
value: '3',
label: '指定'
}],
timerWeekRepeatValue: "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: '',
// 触发器源 1=设备2=定时3=告警输出
triggerSource: [{
value: 1,
label: '设备'
}, {
value: 2,
label: '定时'
}],
// 执行动作源
actionSource: [{
value: 1,
label: '设备'
}, {
value: 3,
label: '告警输出'
}],
// 物模型类别
modelTypes: [{
value: 1,
label: '属性'
}, {
value: 2,
label: '功能'
}],
// 触发器条件
triggerConditions: [{
value: "all",
label: '满足所有条件'
}, {
value: "any",
label: '满足任一条件'
}],
// 告警状态
alertType: [{
value: 1,
label: '启动'
}, {
value: 2,
label: '停止'
}],
// 表单参数
form: {
condition: "all", // 触发器条件
triggers: [],
actions: []
},
// 表单校验
rules: {
alertName: [{
required: true,
message: "告警名称不能为空",
trigger: "blur"
}],
alertLevel: [{
required: true,
message: "告警级别不能为空",
trigger: "change"
}],
productId: [{
required: true,
message: "产品ID不能为空",
trigger: "blur"
}],
productName: [{
required: true,
message: "产品名称不能为空",
trigger: "blur"
}],
triggers: [{
required: true,
message: "触发器不能为空",
trigger: "blur"
}],
actions: [{
required: true,
message: "执行动作不能为空",
trigger: "blur"
}],
}
};
},
created() {
// this.getList();
},
methods: {
/** 查询设备告警列表 */
getList() {
this.loading = true;
listAlert(this.queryParams).then(response => {
this.alertList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
alertId: null,
alertName: null,
alertLevel: null,
productId: null,
productName: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
status: 1,
condition: "all", // 触发器条件
triggers: [{
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
jobId: 0,
cronExpression: "",
isAdvance: 0
}],
actions: [{
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
}]
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.alertId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加自定义告警";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const alertId = row.alertId || this.ids
getAlert(alertId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改设备告警";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.alertId != null) {
updateAlert(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addAlert(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const alertIds = row.alertId || this.ids;
this.$modal.confirm('是否确认删除设备告警编号为"' + alertIds + '"的数据项?').then(function () {
return delAlert(alertIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/alert/export', {
...this.queryParams
}, `alert_${new Date().getTime()}.xlsx`)
},
/** 添加动作 */
addActionItem() {
this.form.actions.push({
id: "",
name: "",
value: ""
})
},
/** 删除动作 */
removeActionItem(index) {
this.form.actions.splice(index, 1);
},
/** 触发器源改变事件 **/
changeTriggerSource() {
this.setTriggerSource();
},
/** 设置触发器源 **/
setTriggerSource() {
// 触发器智能包含一个定时
let hasTimer = false;
for (let i = 0; i < this.form.triggers.length; i++) {
if (this.form.triggers[i].source == 2) {
hasTimer = true;
}
}
if (hasTimer) {
this.triggerSource = [{
value: 1,
label: '设备'
}];
} else {
//定时
this.triggerSource = [{
value: 1,
label: '设备'
}, {
value: 2,
label: '定时'
}];
}
},
/** 添加触发器 */
addTriggerItem() {
this.setTriggerSource();
this.form.triggers.push({
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
jobId: 0,
cronExpression: "",
isAdvance: 0
})
},
/** 删除触发器 */
removeTriggerItem(index) {
this.form.triggers.splice(index, 1);
this.setTriggerSource();
},
/** cron表达式按钮操作 */
handleShowCron(item, index) {
this.expression = item.cronExpression;
this.triggerIndex = index;
this.openCron = true;
},
/** 确定后回传值 */
crontabFill(value) {
this.form.triggers[this.triggerIndex].cronExpression = value;
},
/** 修改重复事件 **/
repeatChange(data) {
if (this.timerWeekRepeatValue == 1) {
// 每天
this.timerWeekValue = [1, 2, 3, 4, 5, 6, 7];
this.form.repeat = 1;
} else if (this.timerWeekRepeatValue == 2) {
// 仅此一次
this.timerWeekValue = [];
this.form.isRepeat = 0;
} else {
// 指定
this.form.isRepeat = 1;
}
this.gentCronExpression();
},
/** 星期改变事件 **/
weekChange(data) {
this.gentCronExpression();
},
/** 时间改变事件 **/
timeChange(data) {
this.gentCronExpression();
},
/**自定义cron表达式选项改变事件 */
customerCronChange(data) {
this.gentCronExpression();
},
/** 生成cron表达式**/
gentCronExpression() {
if (this.timerTimeValue == "") {
this.$modal.alertError("执行时间不能为空");
}
let minute = this.timerTimeValue.substring(0, 2);
let hour = this.timerTimeValue.substring(3);
let week = "*";
if (this.timerWeekValue.length > 0) {
week = this.timerWeekValue;
}
this.form.triggers[this.triggerIndex].cronExpression = "0 " + minute + " " + hour + " ? * " + week;
}
}
};
</script>

View File

@@ -0,0 +1,121 @@
<template>
<div style="padding-left:20px;">
<el-row :gutter="10">
<el-col :span="14">
<el-link type="danger" style="padding-top:5px" :underline="false">该功能未完成</el-link>
<el-table v-loading="loading" :data="modelList" border style="margin-bottom:60px;margin-top:20px;">
<el-table-column label="名称" align="center" prop="modelName" />
<el-table-column label="标识符" align="center" prop="identifier" />
<el-table-column label="物模型类别" align="center" prop="type">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_things_type" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="数据类型" align="center" prop="datatype">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_data_type" :value="scope.row.datatype" />
</template>
</el-table-column>
<el-table-column label="部件" align="center" prop="part">
<template slot-scope="scope">
{{scope.row.part}} 系统定义的部件
</template>
</el-table-column>
</el-table>
<el-divider>高级功能</el-divider>
<el-form ref="form" :model="form" label-width="100px">
<el-form-item label="自定义页面" prop="page">
<el-input v-model="form.page" placeholder="请输入自定义页面" />
</el-form-item>
</el-form>
</el-col>
<el-col :span="8" :offset="2">
<div class="phone">
<div class="phone-container"></div>
</div>
<div style="text-align:center;margin-top:15px;width:370px;">界面展示</div>
</el-col>
</el-row>
</div>
</template>
<script>
import {
listModel,
} from "@/api/iot/model";
export default {
name: "device-log",
dicts: ["iot_things_type", "iot_data_type", "iot_yes_no"],
props: {
product: {
type: Object,
default: null
}
},
data() {
return {
// 遮罩层
loading: false,
// 产品物模型表格数据
modelList: [],
// 弹出层标题
title: "",
// 查询参数
queryParams: {
productId: 0,
// 1-属性2-功能3-事件4-属性和功能
type: 4,
},
form: {},
};
},
watch: {
// 获取到父组件传递的productId后刷新列表
product: function (newVal, oldVal) {
this.productInfo = newVal;
if (this.productInfo && this.productInfo.productId != 0) {
this.queryParams.productId = this.productInfo.productId;
this.getList();
}
}
},
created() {
},
methods: {
/** 查询产品物模型列表 */
getList() {
this.loading = true;
listModel(this.queryParams).then((response) => {
this.modelList = response.rows;
this.total = response.total;
this.loading = false;
});
},
}
};
</script>
<style scoped>
.phone {
height: 700px;
width: 370px;
background-image: url("../../../assets/images/phone.jpg");
background-size: cover;
top: 0px;
}
.phone-container {
height: 620px;
width: 345px;
border-radius: 20px;
position: relative;
top: 45px;
left: 12px;
border: 1px solid #888;
background: linear-gradient(23deg, #AFF7FF 0%, #ffc3a0 100%);
}
</style>

View File

@@ -0,0 +1,288 @@
<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="productName">
<el-input v-model="form.productName" placeholder="请输入产品名称" />
</el-form-item>
<el-form-item label="产品分类" prop="categoryId">
<el-select v-model="form.categoryId" placeholder="请选择分类" @change="selectCategory" style="width:100%">
<el-option v-for="category in categoryShortList" :key="category.id" :label="category.name" :value="category.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="联网方式" prop="networkMethod">
<el-select v-model="form.networkMethod" placeholder="请选择联网方式" style="width:100%;">
<el-option v-for="dict in dict.type.iot_network_method" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
<el-form-item label="备注信息" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" rows="7" />
</el-form-item>
</el-col>
<el-col :span="7">
<el-form-item label="设备类型" prop="deviceType">
<el-select v-model="form.deviceType" placeholder="请选择设备类型" disabled style="width:100%">
<el-option v-for="dict in dict.type.iot_device_type" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
<el-form-item label="设备认证" prop="vertificateMethod">
<el-select v-model="form.vertificateMethod" placeholder="请选择认证方式" disabled style="width:100%">
<el-option v-for="dict in dict.type.iot_vertificate_method" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-form-item>
<el-form-item label="产品编号" prop="productId">
<el-input v-model="form.productId" placeholder="自动生成" :disabled="!form.mqttAccount" readonly />
</el-form-item>
<el-form-item label="Mqtt账号" prop="mqttAccount">
<el-input v-model="form.mqttAccount" placeholder="自动生成" :disabled="!form.mqttAccount" readonly :type="accountInputType">
<el-button slot="append" icon="el-icon-view" style="font-size:18px;" @click="changeInputType('account')"></el-button>
</el-input>
</el-form-item>
<el-form-item label="Mqtt密码" prop="mqttPassword">
<el-input v-model="form.mqttPassword" placeholder="自动生成" :disabled="!form.mqttAccount" readonly :type="passwordInputType">
<el-button slot="append" icon="el-icon-view" style="font-size:18px;" @click="changeInputType('password')"></el-button>
</el-input>
</el-form-item>
<el-form-item label="产品秘钥" prop="mqttSecret">
<el-input v-model="form.mqttSecret" placeholder="自动生成" :disabled="!form.mqttAccount" readonly :type="keyInputType">
<el-button slot="append" icon="el-icon-view" style="font-size:18px;" @click="changeInputType('key')"></el-button>
</el-input>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="产品图片">
<imageUpload ref="image-upload" :value="form.imgUrl" :limit="1" :fileSize="1" @input="getImagePath($event)"></imageUpload>
</el-form-item>
</el-col>
</el-row>
<el-col :span="20">
<el-form-item style="text-align: center;margin:40px 0px;">
<el-button type="primary" @click="submitForm()" v-if="form.status!=2">提交</el-button>
</el-form-item>
</el-col>
</el-form>
</el-tab-pane>
<el-tab-pane label="" name="things" :disabled="form.productId==0">
<span slot="label">* 定义物模型</span>
<product-things-model ref="productThingsModel" :product="form" />
</el-tab-pane>
<el-tab-pane label="" name="alert" disabled>
<span slot="label"> 告警配置</span>
<product-alert ref="productAlert" :product="form"></product-alert>
</el-tab-pane>
<el-tab-pane label="" name="productApp" disabled>
<span slot="label">自定义APP</span>
<product-app ref="productApp" :product="form" />
</el-tab-pane>
<el-tab-pane label="" disabled name="product01" />
<el-tab-pane label="" disabled name="product02" />
<el-tab-pane label="" disabled name="product03" />
<el-tab-pane v-if="form.status==1" name="product04">
<span slot="label">
<el-button type="success" size="mini" @click="changeProductStatus(2)">发布产品</el-button>
</span>
</el-tab-pane>
<el-tab-pane v-if="form.status==2" name="product05">
<span slot="label">
<el-button type="danger" size="mini" @click="changeProductStatus(1)">取消发布</el-button>
</span>
</el-tab-pane>
<el-tab-pane name="product06">
<span slot="label">
<el-button type="info" size="mini" @click="goBack()">返回列表</el-button>
</span>
</el-tab-pane>
</el-tabs>
</el-card>
</template>
<script>
import productThingsModel from "./product-things-model";
import productApp from "./product-app"
import productAlert from "./product-alert"
import imageUpload from "../../../components/ImageUpload/index"
import {
listShortCategory
} from "@/api/iot/category";
import {
getProduct,
addProduct,
updateProduct,
changeProductStatus
} from "@/api/iot/product";
export default {
name: "Product-edit",
dicts: ['iot_device_type', 'iot_network_method', 'iot_vertificate_method'],
components: {
productThingsModel,
productApp,
productAlert,
imageUpload,
},
data() {
return {
// 输入框类型
keyInputType: "password",
accountInputType: "text",
passwordInputType: "password",
// 选中选项卡
activeName: 'basic',
// 分类短列表
categoryShortList: [],
// 表单参数
form: {
networkMethod: 1,
deviceType: 1,
vertificateMethod: 3,
},
// 表单校验
rules: {
productName: [{
required: true,
message: "产品名称不能为空",
trigger: "blur"
}],
categoryId: [{
required: true,
message: "产品分类ID不能为空",
trigger: "blur"
}]
},
};
},
created() {
// 获取产品信息
const productId = this.$route.query && this.$route.query.productId;
this.form.productId = productId;
if (this.form.productId != 0) {
this.getProduct();
}
// 获取简短分类列表
listShortCategory().then(response => {
this.categoryShortList = response.data;
})
},
methods: {
/** 返回按钮 */
goBack() {
const obj = {
path: "/iot/product",
query: {
t: Date.now(),
pageNum: this.$route.query.pageNum
}
};
this.$tab.closeOpenPage(obj);
this.reset();
},
/** 获取产品信息 */
getProduct() {
getProduct(this.form.productId).then(response => {
this.form = response.data;
});
},
// 表单重置
reset() {
this.form = {
productId: 0,
productName: null,
categoryId: null,
categoryName: null,
status: 0,
tslJson: null,
deviceType: 1,
networkMethod: 1,
vertificateMethod: 3,
mqttAccount: null,
mqttPassword: null,
mqttSecret: null,
remark: null
};
this.resetForm("form");
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.productId != null && this.form.productId != 0) {
updateProduct(this.form).then(response => {
this.$modal.alertSuccess("修改成功");
});
} else {
addProduct(this.form).then(response => {
this.$modal.alertSuccess("添加成功,可以开始定义物模型了");
this.form = response.data;
this.activeName = "things";
});
}
}
});
},
/** 更新产品状态 */
changeProductStatus(status) {
let message="发生错误了";
if(status==2){
message="产品发布后不能再更改产品内容和对应物模型 ";
}else if(status==1){
message="产品下不能有已经创建的设备,才能取消发布哦 "
}
this.$confirm(message, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let data = {};
data.productId = this.form.productId;
data.status = status;
changeProductStatus(data).then(response => {
this.$modal.alertSuccess(response.msg);
this.goBack();
}).catch(()=>{
if(status==2){
this.activeName = "things";
}else{
this.goBack();
}
});
}).catch(() => {
this.activeName = "basic";
});
},
/** 选择分类 */
selectCategory(val) {
for (var i = 0; i < this.categoryShortList.length; i++) {
if (this.categoryShortList[i].id == val) {
this.form.categoryName = this.categoryShortList[i].name;
return;
}
}
},
/**获取上传图片的路径 */
getImagePath(data) {
this.form.imgUrl = data;
},
/**改变输入框类型**/
changeInputType(name) {
if (name == "key") {
this.keyInputType = this.keyInputType == "password" ? "text" : "password";
} else if (name == "account") {
this.accountInputType = this.accountInputType == "password" ? "text" : "password";
} else if (name == "password") {
this.passwordInputType = this.passwordInputType == "password" ? "text" : "password";
}
}
}
};
</script>

View File

@@ -0,0 +1,112 @@
<template>
<div style="margin-top:-35px;">
<el-divider></el-divider>
<el-form :model="queryParams" ref="product-select-template" :inline="true" label-width="48px">
<el-form-item label="名称" prop="templateName">
<el-input v-model="queryParams.templateName" placeholder="请输入物模型名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择模型类别" clearable size="small">
<el-option v-for="dict in dict.type.iot_things_type" :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-table v-loading="loading" :data="templateList" @selection-change="handleSelectionChange" ref="selectTemplateTable" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="名称" align="center" prop="templateName" />
<el-table-column label="标识符" align="center" prop="identifier" />
<el-table-column label="物模型类别" align="center" prop="type">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_things_type" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="首页显示" align="center" prop="isTop">
<template slot-scope="scope">
<el-switch v-model="scope.row.isTop" :active-value="1" :inactive-value="0" active-color="#81c0fb" disabled></el-switch>
</template>
</el-table-column>
<el-table-column label="监测值" align="center" prop="isMonitor">
<template slot-scope="scope">
<el-switch v-model="scope.row.isMonitor" :active-value="1" :inactive-value="0" active-color="#81c0fb" disabled></el-switch>
</template>
</el-table-column>
<el-table-column label="数据类型" align="center" prop="datatype">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_data_type" :value="scope.row.datatype" />
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
</div>
</template>
<script>
import {
listTemplate,
} from "@/api/iot/template";
export default {
name: "product-select-template",
dicts: ["iot_things_type", "iot_data_type", "iot_yes_no"],
data() {
return {
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// 通用物模型表格数据
templateList: [],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
templateName: null,
type: null,
},
};
},
created() {
this.getList();
this.ids = [];
},
methods: {
/** 查询通用物模型列表 */
getList() {
this.loading = true;
listTemplate(this.queryParams).then((response) => {
this.templateList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.templateId);
this.single = selection.length !== 1;
this.multiple = !selection.length;
// Id数组传递到父组件
this.$emit('idsToParentEvent', this.ids)
},
},
};
</script>

View File

@@ -0,0 +1,590 @@
<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="handleAdd" v-if="productInfo.status==1">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="el-icon-plus" size="mini" @click="handleSelect" v-if="productInfo.status==1">导入通用物模型</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-plus" size="mini" @click="handleOpenThingsModel">查看物模型</el-button>
</el-col>
<el-col :span="1.5">
<el-link type="danger" style="padding-top:5px" :underline="false">注意标识符不能重复</el-link>
</el-col>
<right-toolbar @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="modelList" border>
<el-table-column label="名称" align="center" prop="modelName" />
<el-table-column label="标识符" align="center" prop="identifier" />
<el-table-column label="首页显示" align="center" prop="isTop" width="100">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isTop" />
</template>
</el-table-column>
<el-table-column label="实时监测" align="center" prop="isMonitor" width="100">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isMonitor" />
</template>
</el-table-column>
<el-table-column label="物模型类别" align="center" prop="type">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_things_type" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="数据类型" align="center" prop="datatype">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_data_type" :value="scope.row.datatype" />
</template>
</el-table-column>
<el-table-column label="数据定义" align="left" prop="specs" min-width="150" class-name="specsColor">
<template slot-scope="scope">
<div v-html="formatSpecsDisplay(scope.row.specs)"></div>
</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)">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改物模型对话框 -->
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="名称" prop="modelName">
<el-input v-model="form.modelName" placeholder="请输入物模型名称,例如:温度" />
</el-form-item>
<el-form-item label="标识符" prop="identifier">
<el-input v-model="form.identifier" placeholder="请输入标识符例如temperature" />
</el-form-item>
<el-form-item label="模型类别" prop="type">
<el-radio-group v-model="form.type" @change="typeChange(form.type)">
<el-radio-button label="1">属性</el-radio-button>
<el-radio-button label="2">功能</el-radio-button>
<el-radio-button label="3">事件</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="首页显示" prop="isTop" v-show="form.type != 3">
<el-switch v-model="form.isTop" active-text="" inactive-text="" :active-value="1" :inactive-value="0" active-color="#13ce66">
</el-switch>
</el-form-item>
<el-form-item label="实时监测" prop="isMonitor" v-show="form.type == 1">
<el-switch v-model="form.isMonitor" active-text="" inactive-text="" :active-value="1" :inactive-value="0" active-color="#13ce66" @change="changeMonitor(form.isMonitor)">
</el-switch>
</el-form-item>
<el-divider></el-divider>
<el-form-item label="数据类型" prop="datatype">
<el-select v-model="form.datatype" placeholder="请选择数据类型" @change="dataTypeChange">
<el-option key="integer" label="整数" value="integer"></el-option>
<el-option key="decimal" label="小数" value="decimal"></el-option>
<el-option key="bool" label="布尔" value="bool" :disabled="form.isMonitor==1"></el-option>
<el-option key="enum" label="枚举" value="enum" :disabled="form.isMonitor==1"></el-option>
<el-option key="string" label="字符串" value="string" :disabled="form.isMonitor==1"></el-option>
<el-option key="array" label="数组" value="array" :disabled="form.isMonitor==1"></el-option>
</el-select>
</el-form-item>
<div v-if="form.datatype == 'integer' || form.datatype == 'decimal'">
<el-form-item label="取值范围">
<el-row>
<el-col :span="9">
<el-input v-model="form.specs.min" placeholder="最小值" type="number" />
</el-col>
<el-col :span="2" align="center"></el-col>
<el-col :span="9">
<el-input v-model="form.specs.max" placeholder="最大值" type="number" />
</el-col>
</el-row>
</el-form-item>
<el-form-item label="单位">
<el-input v-model="form.specs.unit" placeholder="请输入单位,例如:℃" />
</el-form-item>
<el-form-item label="步长">
<el-input v-model="form.specs.step" placeholder="请输入步长例如1" type="number" />
</el-form-item>
</div>
<div v-if="form.datatype == 'bool'">
<el-form-item label="布尔值" prop="">
<el-row style="margin-bottom:10px;">
<el-col :span="11">
<el-input v-model="form.specs.falseText" placeholder="0 对应的文本,例如:关闭" />
</el-col>
<el-col :span="10" :offset="1"> 0 对应文本</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-input v-model="form.specs.trueText" placeholder="1 对应的文本,例如:打开" />
</el-col>
<el-col :span="10" :offset="1"> 1 对应文本</el-col>
</el-row>
</el-form-item>
</div>
<div v-if="form.datatype == 'enum'">
<el-form-item label="枚举项" prop="">
<el-row v-for="(item,index) in form.specs.enumList" :key="index" style="margin-bottom:10px;">
<el-col :span="8">
<el-input v-model="item.value" placeholder="参数值例如0" type="number" />
</el-col>
<el-col :span="12" :offset="1">
<el-input v-model="item.text" placeholder="参数描述,例如:中速档位" />
</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>
</div>
<div v-if="form.datatype == 'string'">
<el-form-item label="最大长度" prop="">
<el-input v-model="form.specs.maxLength" placeholder="请输入字符串最大长度例如1024" type="number" />
</el-form-item>
</div>
<div v-if="form.datatype == 'array'">
<el-form-item label="数组类型" prop="">
<el-radio-group v-model="form.specs.arrayType">
<el-radio label="int">int整数</el-radio>
<el-radio label="double">double小数</el-radio>
<el-radio label="string">string字符串</el-radio>
</el-radio-group>
</el-form-item>
</div>
</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>
<!-- 导入通用物模型对话框 -->
<el-dialog :title="title" :visible.sync="openSelect" width="800px" append-to-body>
<product-select-template ref="productSelectTemplate" @idsToParentEvent="getChildData($event)" />
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="importSelect"> </el-button>
<el-button @click="cancelSelect"> </el-button>
</div>
</el-dialog>
<!-- 物模型JSON -->
<el-dialog :title="title" :visible.sync="openThingsModel" width="600px" append-to-body>
<div style="border:1px solid #ccc;margin-top:-15px;height:600px; overflow:scroll;">
<json-viewer :value="thingsModel" :expand-depth=10 copyable>
<template v-slot:copy>
复制
</template>
</json-viewer>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="info" @click="handleCloseThingsModel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<style>
.specsColor {
background-color: #fcfcfc;
}
</style>
<script>
import productSelectTemplate from "./product-select-template";
import JsonViewer from 'vue-json-viewer'
import 'vue-json-viewer/style.css'
import {
listModel,
getModel,
delModel,
addModel,
updateModel,
importModel
} from "@/api/iot/model";
export default {
name: "product-things-model",
dicts: ["iot_things_type", "iot_data_type", "iot_yes_no"],
components: {
productSelectTemplate,
JsonViewer
},
props: {
product: {
type: Object,
default: null
}
},
watch: {
// 获取到父组件传递的productId后刷新列表
product: function (newVal, oldVal) {
this.productInfo = newVal;
if (this.productInfo && this.productInfo.productId != 0) {
this.queryParams.productId = this.productInfo.productId;
this.getList();
}
}
},
data() {
return {
// 物模型
thingsModel: {},
// 父组件接收的产品信息
productInfo: {},
// 子组件选中的id数组
templateIds: [],
// 遮罩层
loading: false,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 产品物模型表格数据
modelList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
openSelect: false,
openThingsModel: false,
// 查询参数
queryParams: {
productId: 0,
},
// 表单参数
form: {},
// 表单校验
rules: {
modelName: [{
required: true,
message: "物模型名称不能为空",
trigger: "blur"
}],
identifier: [{
required: true,
message: "标识符,产品下唯一不能为空",
trigger: "blur",
}, ],
type: [{
required: true,
message: "模型类别不能为空",
trigger: "change"
}, ],
datatype: [{
required: true,
message: "数据类型不能为空",
trigger: "change"
}, ],
specs: [{
required: true,
message: "数据定义不能为空",
trigger: "blur"
}, ],
},
};
},
created() {
},
methods: {
/** 查询产品物模型列表 */
getList() {
this.loading = true;
listModel(this.queryParams).then((response) => {
this.modelList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
modelId: null,
modelName: null,
productId: null,
productName: null,
tenantId: null,
tenantName: null,
identifier: null,
type: null,
datatype: null,
isSys: null,
isTop: null,
isMonitor: null,
delFlag: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
specs: null,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加物模型";
this.form.type = 1;
this.form.datatype = "integer"
this.form.specs = {
enumList: [],
};
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const modelId = row.modelId;
getModel(modelId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改物模型";
// Json转对象
this.form.specs = JSON.parse(this.form.specs);
});
},
/**查看物模型 */
handleOpenThingsModel() {
this.title = "物模型";
// 生成物模型
this.thingsModel = {
properties: [],
functions: [],
events: []
}
for (var i = 0; i < this.modelList.length; i++) {
let thingsItem = {};
thingsItem.id = this.modelList[i].identifier;
thingsItem.name = this.modelList[i].modelName;
if (this.modelList[i].type == 1) {
//属性
thingsItem.isTop = this.modelList[i].isTop;
thingsItem.isMonitor = this.modelList[i].isMonitor;
thingsItem.datatype = JSON.parse(this.modelList[i].specs);
this.thingsModel.properties.push(thingsItem);
} else if (this.modelList[i].type == 2) {
// 功能
thingsItem.isTop = this.modelList[i].isTop;
thingsItem.datatype = JSON.parse(this.modelList[i].specs);
this.thingsModel.functions.push(thingsItem);
} else if (this.modelList[i].type == 3) {
// 事件
thingsItem.datatype = JSON.parse(this.modelList[i].specs);
this.thingsModel.events.push(thingsItem);
}
}
this.openThingsModel = true;
},
/**关闭物模型 */
handleCloseThingsModel() {
this.openThingsModel = false;
},
/** 选择物模型 */
handleSelect() {
this.openSelect = true;
this.title = "导入通用物模型";
this.form.type = 1;
this.form.datatype = "integer"
this.form.specs = {
enumList: [],
};
},
// 取消导入通用物模型按钮
cancelSelect() {
this.openSelect = false;
this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection();
},
// 获取子组件的值
getChildData(data) {
this.templateIds = data;
},
// 导入通用物模型按钮
importSelect() {
if (this.templateIds != null && this.templateIds.length > 0) {
var importData = {
productId: this.productInfo.productId,
productName: this.productInfo.productName,
templateIds: this.templateIds
}
importModel(importData).then(response => {
this.$modal.msgSuccess(response.msg);
this.openSelect = false;
this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection();
this.getList();
});
}
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (this.form.modelId != null) {
// 格式化specs
this.form.specs = this.formatThingsSpecs();
if (this.form.type == 2) {
this.form.isMonitor = 0;
} else if (this.form.type == 3) {
this.form.isMonitor = 0;
this.form.isTop = 0;
}
updateModel(this.form).then((response) => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
// 格式化specs
this.form.specs = this.formatThingsSpecs();
this.form.productId = this.productInfo.productId;
this.form.productName = this.productInfo.productName;
if (this.form.type == 2) {
this.form.isMonitor = 0;
} else if (this.form.type == 3) {
this.form.isMonitor = 0;
this.form.isTop = 0;
}
addModel(this.form).then((response) => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const modelIds = row.modelId;
this.$modal
.confirm('是否确认删除物模型编号为"' + modelIds + '"的数据项?')
.then(function () {
return delModel(modelIds);
})
.then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download(
"iot/model/export", {
...this.queryParams,
},
`model_${new Date().getTime()}.xlsx`
);
},
// 类型改变
typeChange(label) {
if (label == 2 || label == 3) {
this.form.isMonitor = 0;
}
},
// 实时监测改变
changeMonitor(isMonitor) {
if (isMonitor == 1 && this.form.datatype != "integer" && this.form.datatype != "decimal") {
this.form.datatype = "integer";
}
},
// 格式化物模型
formatThingsSpecs() {
var data = {};
data.type = this.form.datatype;
if (this.form.datatype == "integer" || this.form.datatype == "decimal") {
data.min = Number(this.form.specs.min);
data.max = Number(this.form.specs.max);
data.unit = this.form.specs.unit;
data.step = Number(this.form.specs.step);
} else if (this.form.datatype == "string") {
data.maxLength = Number(this.form.specs.maxLength);
} else if (this.form.datatype == "bool") {
data.falseText = this.form.specs.falseText;
data.trueText = this.form.specs.trueText;
} else if (this.form.datatype == "array") {
data.arrayType = this.form.specs.arrayType;
} else if (this.form.datatype == "enum") {
data.enumList = this.form.specs.enumList;
}
return JSON.stringify(data);
},
/** 切换为枚举项 */
dataTypeChange(val) {
if (val == "enum") {
this.form.specs.enumList = [{
value: "",
text: ""
}];
} else if (val == "array") {
this.form.specs.arrayType = "int";
}
},
/** 添加枚举项 */
addEnumItem() {
this.form.specs.enumList.push({
value: "",
text: ""
})
},
/** 删除枚举项 */
removeEnumItem(index) {
this.form.specs.enumList.splice(index, 1);
},
/** 格式化显示数据定义 */
formatSpecsDisplay(json) {
let specs = JSON.parse(json);
if (specs.type === "integer" || specs.type === "decimal") {
return "<span style='width:50%;display:inline-block;'>最大值:<span style=\"color:#F56C6C\">" + specs.max +
"</span></span>最小值:<span style=\"color:#F56C6C\">" + specs.min +
"</span><br /><span style='width:50%;display:inline-block;'>步长:<span style=\"color:#F56C6C\">" + specs.step +
"</span></span>单位:<span style=\"color:#F56C6C\">" + specs.unit;
} else if (specs.type === "string") {
return "最大长度:<span style=\"color:#F56C6C\">" + specs.maxLength + "</span>";
} else if (specs.type === "array") {
return "数组类型:<span style=\"color:#F56C6C\">" + specs.arrayType + "</span>";
} else if (specs.type === "enum") {
let items = "";
for (let i = 0; i < specs.enumList.length; i++) {
items = items + "<span style='width:50%;display:inline-block;'>" + specs.enumList[i].value + "<span style='color:#F56C6C'>" + specs.enumList[i].text + "</span></span>"
if (i > 0 && i % 2 != 0) {
items = items + "<br />"
}
}
return items;
} else if (specs.type === "bool") {
return "<span style='width:50%;display:inline-block;'>0<span style=\"color:#F56C6C\">" + specs.falseText +
"</span></span>1<span style=\"color:#F56C6C\">" + specs.trueText
}
},
},
};
</script>

View File

@@ -0,0 +1,624 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<div style="height:50px; color:#F56C6C;margin-left:20px;">该功能下个版本发布</div>
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="场景名称" prop="sceneName">
<el-input v-model="queryParams.sceneName" 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-card>
<el-card style="padding-bottom:100px;">
<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:scene: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:scene:edit']">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="el-icon-delete" size="mini" disabled @click="handleDelete" v-hasPermi="['iot:scene: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:scene:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="sceneList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="场景名称" align="center" prop="sceneName" />
<el-table-column label="用户ID" align="center" prop="userId" />
<el-table-column label="用户名称" align="center" prop="userName" />
<el-table-column label="触发器" align="center" prop="triggers" />
<el-table-column label="执行动作" align="center" prop="actions" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<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:scene:edit']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:scene:remove']" disabled>删除</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="80px">
<el-row>
<el-col :span="16">
<el-form-item label="场景名称" prop="sceneName">
<el-input v-model="form.sceneName" placeholder="请输入场景名称" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="触发器" prop="griggers">
<el-select v-model="form.condition" placeholder="请选择" size="small" style="margin-bottom:10px;">
<el-option v-for="item in triggerConditions" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
<div v-for="(item,index) in form.triggers" :key="index" style="margin-bottom:15px;border:1px solid #ddd;padding:10px;">
<el-row>
<el-col :span="4">
<el-select v-model="item.source" placeholder="请选择" size="small" @change="changeTriggerSource">
<el-option v-for="subItem in triggerSource" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="16" :offset="1" v-if="item.source==1">
<el-link :underline="false">请选择一个设备<i class="el-icon-edit el-icon--right"></i></el-link>
</el-col>
<el-col :span="16" :offset="1" v-if="item.source==2">
<el-time-picker v-model="timerTimeValue" size="small" value-format="HH:mm" placeholder="选择执行时间" @change="timeChange" :disabled="item.isAdvance==1"></el-time-picker>
</el-col>
<el-col :span="2" :offset="1" v-if="index!=0"><a style="color:#F56C6C" @click="removeTriggerItem(index)">删除</a></el-col>
</el-row>
<!--设备-->
<el-row v-if="item.source==1">
<el-col :span="4">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="4" :offset="1">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="5" :offset="1">
<el-select v-model="item.operator" placeholder="请选择操作符" size="small">
<el-option key="=" label="等于(=)" value="=" />
<el-option key="!=" label="不等于(!=)" value="!=" />
<el-option key=">" label="大于(>)" value=">" />
<el-option key="<" label="小于(<)" value="<" />
<el-option key=">=" label="大于等于(>=)" value=">=" />
<el-option key="<=" label="小于等于(<=)" value="<=" />
<el-option key="contain" label="包含(contain)" value="contain" />
<el-option key="notcontain" label="不包含(not contain)" value="notcontain" />
</el-select>
</el-col>
<el-col :span="5" :offset="1">
<el-input v-model="item.value" placeholder="值" size="small" />
</el-col>
</el-row>
<!--定时-->
<el-row v-if="item.source==2">
<el-col :span="24">
<el-row style="margin-bottom:5px;">
<el-col :span="4">
<el-select v-model="timerWeekRepeatValue" placeholder="请选择" @change="repeatChange" size="small" :disabled="item.isAdvance==1">
<el-option v-for="item in timerWeekRepeats" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-col>
<el-col :span="15" :offset="1" v-if="timerWeekRepeatValue==3">
<el-select v-model="timerWeekValue" placeholder="请选择" multiple style="width:485px" @change="weekChange" size="small" :disabled="item.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-col>
<el-col :span="24">
<el-row>
<el-col :span="18">
<el-input v-model="item.cronExpression" placeholder="cron执行表达式" :disabled="item.isAdvance==0" size="small">
<template slot="append">
<el-button type="primary" @click="handleShowCron(item,index)" :disabled="item.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="item.isAdvance" :true-label="1" :false-label="0" @change="customerCronChange">自定义表达式</el-checkbox>
</el-col>
</el-row>
</el-col>
</el-row>
</div>
<div>+ <a style="color:#409EFF" @click="addTriggerItem()">添加触发器</a></div>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="执行动作">
<div v-for="(item,index) in form.actions" :key="index" style="margin-bottom:15px;border:1px solid #ddd;padding:10px;">
<el-row>
<el-col :span="4">
<el-select v-model="item.source" placeholder="请选择" size="small">
<el-option v-for="subItem in actionSource" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="10" :offset="1" v-if="item.source==1">
<el-link :underline="false">请选择一个设备<i class="el-icon-edit el-icon--right"></i></el-link>
</el-col>
</el-row>
<!---设备-->
<el-row v-if="item.source==1">
<el-col :span="4">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="4" :offset="1">
<el-select v-model="item.modelType" placeholder="请选择" size="small">
<el-option v-for="subItem in modelTypes" :key="subItem.value" :label="subItem.label" :value="subItem.value">
</el-option>
</el-select>
</el-col>
<el-col :span="11" :offset="1">
<el-input v-model="item.value" placeholder="值" size="small" />
</el-col>
<el-col :span="2" :offset="1" v-if="index!=0"><a style="color:#F56C6C" @click="removeActionItem(index)">删除</a></el-col>
</el-row>
<!--告警输出-->
<el-row v-if="item.source==3">
<el-col :span="4">
<el-select v-model="item.alertLevel" placeholder="告警级别" size="small">
<el-option v-for="dict in dict.type.iot_alert_level" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
</el-select>
</el-col>
<el-col :span="16" :offset="1">
<el-input v-model="item.alertName" placeholder="请输入告警名称" size="small" />
</el-col>
</el-row>
</div>
<div>+ <a style="color:#409EFF" @click="addActionItem()">添加执行动作</a></div>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" disabled> </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-card>
</div>
</template>
<script>
import {
listScene,
getScene,
delScene,
addScene,
updateScene
} from "@/api/iot/scene";
import Crontab from '@/components/Crontab'
export default {
components: {
Crontab
},
name: "Scene",
dicts: ['iot_alert_level'],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 场景联动表格数据
sceneList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 是否显示Cron表达式弹出层
openCron: false,
// 传入的表达式
expression: "",
// 触发器的索引,用于接收传入的表达式
triggerIndex:0,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
sceneName: null,
userId: null,
userName: null,
},
// 周
timerWeekRepeats: [{
value: '1',
label: '每天'
}, {
value: '2',
label: '仅此一次'
}, {
value: '3',
label: '指定'
}],
timerWeekRepeatValue: "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: '',
// 触发器源 1=设备2=定时3=告警输出
triggerSource: [{
value: 1,
label: '设备'
}, {
value: 2,
label: '定时'
}],
// 执行动作源
actionSource: [{
value: 1,
label: '设备'
}, {
value: 3,
label: '告警输出'
}],
// 物模型类别
modelTypes: [{
value: 1,
label: '属性'
}, {
value: 2,
label: '功能'
}],
// 触发器条件
triggerConditions: [{
value: "all",
label: '满足所有条件'
}, {
value: "any",
label: '满足任一条件'
}],
// 表单参数
form: {
condition: "all", // 触发器条件
triggers: [],
actions: []
},
// 表单校验
rules: {
sceneName: [{
required: true,
message: "场景名称不能为空",
trigger: "blur"
}],
userId: [{
required: true,
message: "用户ID不能为空",
trigger: "blur"
}],
userName: [{
required: true,
message: "用户名称不能为空",
trigger: "blur"
}],
triggers: [{
required: true,
message: "触发器不能为空",
trigger: "blur"
}],
actions: [{
required: true,
message: "执行动作不能为空",
trigger: "blur"
}],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询场景联动列表 */
getList() {
this.loading = true;
listScene(this.queryParams).then(response => {
this.sceneList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
sceneId: null,
sceneName: null,
userId: null,
userName: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
condition: "all", // 触发器条件
triggers: [{
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
jobId: 0,
cronExpression: "",
isAdvance: 0
}],
actions: [{
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
}]
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.sceneId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加场景联动";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const sceneId = row.sceneId || this.ids
getScene(sceneId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改场景联动";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.sceneId != null) {
updateScene(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addScene(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const sceneIds = row.sceneId || this.ids;
this.$modal.confirm('是否确认删除场景联动编号为"' + sceneIds + '"的数据项?').then(function () {
return delScene(sceneIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('iot/scene/export', {
...this.queryParams
}, `scene_${new Date().getTime()}.xlsx`)
},
/** 添加动作 */
addActionItem() {
this.form.actions.push({
id: "",
name: "",
value: ""
})
},
/** 删除动作 */
removeActionItem(index) {
this.form.actions.splice(index, 1);
},
/** 触发器源改变事件 **/
changeTriggerSource(data) {
this.setTriggerSource();
},
/** 设置触发器源 **/
setTriggerSource() {
// 触发器智能包含一个定时
let hasTimer = false;
for (let i = 0; i < this.form.triggers.length; i++) {
if (this.form.triggers[i].source == 2) {
hasTimer = true;
this.triggerIndex=i;
}
}
if (hasTimer) {
this.triggerSource = [{
value: 1,
label: '设备'
}];
} else {
//定时
this.triggerSource = [{
value: 1,
label: '设备'
}, {
value: 2,
label: '定时'
}];
}
},
/** 添加触发器 */
addTriggerItem() {
this.setTriggerSource();
this.form.triggers.push({
id: "",
name: "",
value: "",
deviceId: 0,
deviceName: "请选择一个设备",
source: 1, //1=设备2=定时3=告警输出
modelType: 1, // 1=属性2=功能
jobId: 0,
cronExpression: "",
isAdvance: 0
})
},
/** 删除触发器 */
removeTriggerItem(index) {
this.form.triggers.splice(index, 1);
this.setTriggerSource();
},
/** cron表达式按钮操作 */
handleShowCron(item,index) {
this.expression=item.cronExpression;
this.triggerIndex=index;
this.openCron = true;
},
/** 确定后回传值 */
crontabFill(value) {
this.form.triggers[this.triggerIndex].cronExpression = value;
},
/** 修改重复事件 **/
repeatChange(data) {
if (this.timerWeekRepeatValue == 1) {
// 每天
this.timerWeekValue = [1, 2, 3, 4, 5, 6, 7];
this.form.isRepeat = 1;
} else if (this.timerWeekRepeatValue == 2) {
// 仅此一次
this.timerWeekValue = [];
this.form.isRepeat = 0;
} else {
// 指定
this.form.isRepeat = 1;
}
this.gentCronExpression();
},
/** 星期改变事件 **/
weekChange(data) {
this.gentCronExpression();
},
/** 时间改变事件 **/
timeChange(data) {
this.gentCronExpression();
},
/**自定义cron表达式选项改变事件 */
customerCronChange(data){
this.gentCronExpression();
},
/** 生成cron表达式**/
gentCronExpression() {
if (this.timerTimeValue == "") {
this.$modal.alertError("执行时间不能为空");
}
let minute = this.timerTimeValue.substring(0, 2);
let hour = this.timerTimeValue.substring(3);
let week = "*";
if (this.timerWeekValue.length > 0) {
week = this.timerWeekValue;
}
this.form.triggers[this.triggerIndex].cronExpression = "0 " + minute + " " + hour + " ? * " + week;
}
}
};
</script>

View File

@@ -0,0 +1,497 @@
<template>
<div style="padding:6px;">
<el-card v-show="showSearch" style="margin-bottom:6px;">
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom:-20px;">
<el-form-item label="名称" prop="templateName">
<el-input v-model="queryParams.templateName" placeholder="请输入物模型名称" clearable size="small" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item label="类别" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择模型类别" clearable size="small">
<el-option v-for="dict in dict.type.iot_things_type" :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-card>
<el-card style="padding-bottom:100px;">
<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:template: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:template: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:template: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:template:export']">导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="templateList" @selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="名称" align="center" prop="templateName" />
<el-table-column label="标识符" align="center" prop="identifier" />
<el-table-column label="首页显示" align="center" prop="isTop" width="80">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isTop" />
</template>
</el-table-column>
<el-table-column label="监测值" align="center" prop="isMonitor" width="80">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isMonitor" />
</template>
</el-table-column>
<el-table-column label="系统定义" align="center" prop="isSys" width="80">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_yes_no" :value="scope.row.isSys" />
</template>
</el-table-column>
<el-table-column label="物模型类别" align="center" prop="type">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_things_type" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="数据类型" align="center" prop="datatype">
<template slot-scope="scope">
<dict-tag :options="dict.type.iot_data_type" :value="scope.row.datatype" />
</template>
</el-table-column>
<el-table-column label="数据定义" align="left" prop="specs" min-width="150" class-name="specsColor">
<template slot-scope="scope">
<div v-html="formatSpecsDisplay(scope.row.specs)"></div>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="small" type="primary" style="padding:5px;" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['iot:template:edit']">修改</el-button>
<el-button size="small" type="danger" style="padding:5px;" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['iot:template:remove']">删除</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="600px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="名称" prop="templateName">
<el-input v-model="form.templateName" placeholder="请输入物模型名称,例如:温度" />
</el-form-item>
<el-form-item label="标识符" prop="identifier">
<el-input v-model="form.identifier" placeholder="请输入标识符例如temperature" />
</el-form-item>
<el-form-item label="模型类别" prop="type">
<el-radio-group v-model="form.type" @change="typeChange(form.type)">
<el-radio-button label="1">属性</el-radio-button>
<el-radio-button label="2">功能</el-radio-button>
<el-radio-button label="3">事件</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="首页显示" prop="isTop" v-show="form.type != 3">
<el-switch v-model="form.isTop" active-text="" inactive-text="" :active-value="1" :inactive-value="0" active-color="#13ce66">
</el-switch>
</el-form-item>
<el-form-item label="实时监测" prop="isMonitor" v-show="form.type == 1">
<el-switch v-model="form.isMonitor" active-text="" inactive-text="" :active-value="1" :inactive-value="0" active-color="#13ce66" @change="changeMonitor(form.isMonitor)">
</el-switch>
</el-form-item>
<el-divider></el-divider>
<el-form-item label="数据类型" prop="datatype">
<el-select v-model="form.datatype" placeholder="请选择数据类型" @change="dataTypeChange">
<el-option key="integer" label="整数" value="integer"></el-option>
<el-option key="decimal" label="小数" value="decimal"></el-option>
<el-option key="bool" label="布尔" value="bool" :disabled="form.isMonitor==1"></el-option>
<el-option key="enum" label="枚举" value="enum" :disabled="form.isMonitor==1"></el-option>
<el-option key="string" label="字符串" value="string" :disabled="form.isMonitor==1"></el-option>
<el-option key="array" label="数组" value="array" :disabled="form.isMonitor==1"></el-option>
</el-select>
</el-form-item>
<div v-if="form.datatype == 'integer' || form.datatype == 'decimal'">
<el-form-item label="取值范围">
<el-row>
<el-col :span="9">
<el-input v-model="form.specs.min" placeholder="最小值" type="number" />
</el-col>
<el-col :span="2" align="center"></el-col>
<el-col :span="9">
<el-input v-model="form.specs.max" placeholder="最大值" type="number" />
</el-col>
</el-row>
</el-form-item>
<el-form-item label="单位">
<el-input v-model="form.specs.unit" placeholder="请输入单位,例如:℃" />
</el-form-item>
<el-form-item label="步长">
<el-input v-model="form.specs.step" placeholder="请输入步长例如1" type="number" />
</el-form-item>
</div>
<div v-if="form.datatype == 'bool'">
<el-form-item label="布尔值" prop="">
<el-row style="margin-bottom:10px;">
<el-col :span="11">
<el-input v-model="form.specs.falseText" placeholder="0 对应的文本,例如:关闭" />
</el-col>
<el-col :span="10" :offset="1"> 0 对应文本</el-col>
</el-row>
<el-row>
<el-col :span="11">
<el-input v-model="form.specs.trueText" placeholder="1 对应的文本,例如:打开" />
</el-col>
<el-col :span="10" :offset="1"> 1 对应文本</el-col>
</el-row>
</el-form-item>
</div>
<div v-if="form.datatype == 'enum'">
<el-form-item label="枚举项" prop="">
<el-row v-for="(item,index) in form.specs.enumList" :key="index" style="margin-bottom:10px;">
<el-col :span="8">
<el-input v-model="item.value" placeholder="参数值例如0" type="number" />
</el-col>
<el-col :span="12" :offset="1">
<el-input v-model="item.text" placeholder="参数描述,例如:中速档位" />
</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>
</div>
<div v-if="form.datatype == 'string'">
<el-form-item label="最大长度" prop="">
<el-input v-model="form.specs.maxLength" placeholder="请输入字符串最大长度例如1024" type="number" />
</el-form-item>
</div>
<div v-if="form.datatype == 'array'">
<el-form-item label="数组类型" prop="">
<el-radio-group v-model="form.specs.arrayType">
<el-radio label="int">int整数</el-radio>
<el-radio label="double">double小数</el-radio>
<el-radio label="string">string字符串</el-radio>
</el-radio-group>
</el-form-item>
</div>
</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>
</el-card>
</div>
</template>
<style>
.specsColor {
background-color: #fcfcfc;
}
</style>
<script>
import {
listTemplate,
getTemplate,
delTemplate,
addTemplate,
updateTemplate,
} from "@/api/iot/template";
export default {
name: "Template",
dicts: ["iot_things_type", "iot_data_type", "iot_yes_no"],
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 通用物模型表格数据
templateList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
templateName: null,
type: null,
},
// 表单参数
form: {},
// 表单校验
rules: {
templateName: [{
required: true,
message: "物模型名称不能为空",
trigger: "blur"
}, ],
identifier: [{
required: true,
message: "标识符,产品下唯一不能为空",
trigger: "blur",
}, ],
type: [{
required: true,
message: "模型类别不能为空",
trigger: "change"
}, ],
datatype: [{
required: true,
message: "数据类型不能为空",
trigger: "change"
}, ],
specs: [{
required: true,
message: "数据定义不能为空",
trigger: "blur"
}, ],
},
};
},
created() {
this.getList();
},
methods: {
/** 查询通用物模型列表 */
getList() {
this.loading = true;
listTemplate(this.queryParams).then((response) => {
this.templateList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
templateId: null,
templateName: null,
userId: null,
userName: null,
tenantId: null,
tenantName: null,
identifier: null,
type: null,
datatype: null,
isSys: null,
isTop: null,
isMonitor: null,
delFlag: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null,
specs: 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.templateId);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加通用物模型";
this.form.type = 1;
this.form.datatype = "integer"
this.form.specs = {
enumList: [],
};
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const templateId = row.templateId || this.ids;
getTemplate(templateId).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改通用物模型";
// Json转对象
this.form.specs = JSON.parse(this.form.specs);
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (this.form.templateId != null) {
// 格式化specs
this.form.specs = this.formatThingsSpecs();
if (this.form.type == 2) {
this.form.isMonitor = 0;
} else if (this.form.type == 3) {
this.form.isMonitor = 0;
this.form.isTop = 0;
}
updateTemplate(this.form).then((response) => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
// 格式化specs
this.form.specs = this.formatThingsSpecs();
if (this.form.type == 2) {
this.form.isMonitor = 0;
} else if (this.form.type == 3) {
this.form.isMonitor = 0;
this.form.isTop = 0;
}
addTemplate(this.form).then((response) => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const templateIds = row.templateId || this.ids;
this.$modal
.confirm('是否确认删除通用物模型编号为"' + templateIds + '"的数据项?')
.then(function () {
return delTemplate(templateIds);
})
.then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download(
"iot/template/export", {
...this.queryParams,
},
`template_${new Date().getTime()}.xlsx`
);
},
// 类型改变
typeChange(label){
if(label==2 || label==3){
this.form.isMonitor=0;
}
},
// 实时监测改变
changeMonitor(isMonitor){
if(isMonitor==1 && this.form.datatype!="integer" && this.form.datatype!="decimal"){
this.form.datatype="integer";
}
},
// 格式化物模型
formatThingsSpecs() {
var data = {};
data.type = this.form.datatype;
if (this.form.datatype == "integer" || this.form.datatype == "decimal") {
data.min = Number(this.form.specs.min);
data.max = Number(this.form.specs.max);
data.unit = this.form.specs.unit;
data.step = Number(this.form.specs.step);
} else if (this.form.datatype == "string") {
data.maxLength = Number(this.form.specs.maxLength);
} else if (this.form.datatype == "bool") {
data.falseText = this.form.specs.falseText;
data.trueText = this.form.specs.trueText;
} else if (this.form.datatype == "array") {
data.arrayType = this.form.specs.arrayType;
} else if (this.form.datatype == "enum") {
data.enumList = this.form.specs.enumList;
}
return JSON.stringify(data);
},
/** 切换为枚举项 */
dataTypeChange(val) {
if (val == "enum") {
this.form.specs.enumList = [{
value: "",
text: ""
}];
} else if (val == "array") {
this.form.specs.arrayType = "int";
}
},
/** 添加枚举项 */
addEnumItem() {
this.form.specs.enumList.push({
value: "",
text: ""
})
},
/** 删除枚举项 */
removeEnumItem(index) {
this.form.specs.enumList.splice(index, 1);
},
/** 格式化显示数据定义 */
formatSpecsDisplay(json) {
let specs = JSON.parse(json);
if (specs.type === "integer" || specs.type === "decimal") {
return "<span style='width:50%;display:inline-block;'>最大值:<span style=\"color:#F56C6C\">" + specs.max +
"</span></span>最小值:<span style=\"color:#F56C6C\">" + specs.min +
"</span><br /><span style='width:50%;display:inline-block;'>步长:<span style=\"color:#F56C6C\">" + specs.step +
"</span></span>单位:<span style=\"color:#F56C6C\">" + specs.unit;
} else if (specs.type === "string") {
return "最大长度:<span style=\"color:#F56C6C\">" + specs.maxLength + "</span>";
} else if (specs.type === "array") {
return "数组类型:<span style=\"color:#F56C6C\">" + specs.arrayType + "</span>";
} else if (specs.type === "enum") {
let items = "";
for (let i = 0; i < specs.enumList.length; i++) {
items = items + "<span style='width:50%;display:inline-block;'>" + specs.enumList[i].value + "<span style='color:#F56C6C'>" + specs.enumList[i].text + "</span></span>"
if (i > 0 && i % 2 != 0) {
items = items + "<br />"
}
}
return items;
} else if (specs.type === "bool") {
return "<span style='width:50%;display:inline-block;'>0<span style=\"color:#F56C6C\">" + specs.falseText +
"</span></span>1<span style=\"color:#F56C6C\">" + specs.trueText
}
},
},
};
</script>