index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <!--传感器管理-->
  2. <template>
  3. <div class="app-container sensor">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="form-box">
  5. <el-form-item label="学院" prop="deptId">
  6. <el-select v-model="queryParams.deptId" placeholder="请选择学院" @change="handleNodeClick">
  7. <el-option
  8. v-for="dict in deptOptions"
  9. :key="dict.deptId"
  10. :label="dict.deptName"
  11. :value="dict.deptId"
  12. ></el-option>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="实验室" prop="subjectId">
  16. <el-select v-model="queryParams.subjectId" placeholder="请选择实验室">
  17. <el-option
  18. v-for="item in subjectOptions"
  19. :key="item.id"
  20. :label="item.name"
  21. :value="item.id">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="状态" prop="senseState">
  26. <el-select v-model="queryParams.senseState" placeholder="请选择状态" clearable size="small">
  27. <el-option label="离线" value="OFFLINE" />
  28. <el-option label="在线" value="TURN_ON" />
  29. <el-option label="异常" value="ERROR" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item style="float: right;">
  33. <el-col :span="1.5">
  34. <p class="add-button-one-120"
  35. @click="handleAdd"
  36. v-hasPermi="['laboratory:sensor:add']"
  37. ><i class="el-icon-plus"></i>新增传感器</p>
  38. </el-col>
  39. </el-form-item>
  40. <el-form-item>
  41. <p class="inquire-button-one" @click="handleQuery">查询</p>
  42. <p class="reset-button-one" @click="resetQuery">重置</p>
  43. </el-form-item>
  44. </el-form>
  45. <el-table v-loading="loading" border :data="sensorList" @selection-change="handleSelectionChange">
  46. <el-table-column label="名称" align="left" prop="name" />
  47. <el-table-column label="网关编号" align="left" prop="gatewayId" />
  48. <el-table-column label="学院" align="left" prop="deptName" />
  49. <el-table-column label="实验室" align="left" prop="subjectName" />
  50. <el-table-column label="路由" align="left" prop="routeNum" />
  51. <el-table-column label="状态" align="left" prop="senseState">
  52. <template slot-scope="scope">{{scope.row.senseState==null?'-':scope.row.senseState.name}}</template>
  53. </el-table-column>
  54. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
  55. <template slot-scope="scope">
  56. <div class="button-box">
  57. <p class="table-min-button"
  58. @click="handleUpdate(scope.row)"
  59. style="margin-right:20px;"
  60. v-hasPermiAnd="['laboratory:sensor:query','laboratory:sensor:edit']"
  61. >编辑</p>
  62. <p class="table-min-button"
  63. @click="handleDelete(scope.row)"
  64. v-hasPermi="['laboratory:sensor:remove']"
  65. >删除</p>
  66. </div>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <pagination :page-sizes="[20, 30, 40, 50]"
  71. v-show="total>0"
  72. :total="total"
  73. layout="total, prev, pager, next, sizes, jumper"
  74. :page.sync="queryParams.pageNum"
  75. :limit.sync="queryParams.pageSize"
  76. @pagination="getList"
  77. />
  78. <!-- 添加或修改传感器对话框 -->
  79. <el-dialog :title="title" :visible.sync="open" width="520px" append-to-body class="sensor-dialog-box">
  80. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  81. <el-form-item label="传感器名称" prop="name">
  82. <el-input v-model="form.name" placeholder="请输入传感器名称" maxlength="20" />
  83. </el-form-item>
  84. <el-form-item label="传感器类型" prop="type">
  85. <el-select v-model="form.type" placeholder="请选择传感器类型">
  86. <el-option
  87. v-for="item in sensorAddOptions"
  88. :key="item.enumName"
  89. :label="item.name"
  90. :value="item.enumName">
  91. </el-option>
  92. </el-select>
  93. </el-form-item>
  94. <el-form-item label="网关编号" >
  95. <el-input v-model="form.gatewayId" maxlength="20" placeholder="请输入网关编号" />
  96. </el-form-item>
  97. <el-form-item label="路由" prop="routeNum">
  98. <el-input-number v-model="form.routeNum" :min="0" :max="99" label="描述文字"></el-input-number>
  99. </el-form-item>
  100. <el-form-item label="传感器对应名称" prop="configName">
  101. <el-input v-model="form.configName" maxlength="20" placeholder="传感器对应名称"></el-input>
  102. </el-form-item>
  103. <el-form-item label="传感器对应状态" prop="configStatus">
  104. <el-input v-model="form.configStatus" maxlength="20" placeholder="传感器对应状态"></el-input>
  105. </el-form-item>
  106. <!--
  107. <el-form-item label="检测数据" prop="senseData">
  108. <el-input type="number" v-model="form.senseData" placeholder="请输入检测数据" />
  109. </el-form-item>
  110. <el-form-item label="数据上限" prop="dataUpper">
  111. <el-input type="number" v-model="form.dataUpper" placeholder="请输入数据上限" />
  112. </el-form-item>
  113. <el-form-item label="数据下限" prop="dataLower">
  114. <el-input type="number" v-model="form.dataLower" placeholder="请输入数据下限" />
  115. </el-form-item>
  116. <el-form-item label="mac地址" prop="macAdd">
  117. <el-input v-model="form.macAdd" placeholder="请输入mac地址" />
  118. </el-form-item>
  119. -->
  120. <el-form-item label="实验室" prop="subjectId">
  121. <el-select v-model="form.subjectId" placeholder="请选择实验室">
  122. <el-option
  123. v-for="item in subjectAddOptions"
  124. :key="item.id"
  125. :label="item.name"
  126. :value="item.id">
  127. </el-option>
  128. </el-select>
  129. </el-form-item>
  130. <!--<el-form-item label="实验室" prop="type">-->
  131. <!--<el-select v-model="form.type" placeholder="请选择实验室">-->
  132. <!--<el-option label="请选择字典生成" value="" />-->
  133. <!--</el-select>-->
  134. <!--</el-form-item>-->
  135. </el-form>
  136. <div slot="footer" class="dialog-footer">
  137. <el-button @click="cancel">取 消</el-button>
  138. <el-button type="primary" @click="submitForm">确 定</el-button>
  139. </div>
  140. </el-dialog>
  141. </div>
  142. </template>
  143. <script>
  144. import mqtt from 'mqtt'
  145. import { listSensor, getSensor, delSensor, addSensor, updateSensor,getSensorList } from "@/api/laboratory/sensor";
  146. import { listDepartments } from "@/api/system/dept";
  147. import { subjectDictList } from "@/api/laboratory/group";
  148. import { treeselect } from "@/api/system/dept";
  149. import Treeselect from "@riophae/vue-treeselect";
  150. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  151. export default {
  152. name: "Sensor",
  153. components: { Treeselect },
  154. data() {
  155. return {
  156. tableButtonType:this.hasPermiDom(['laboratory:sensor:query','laboratory:sensor:edit','laboratory:sensor:remove']),
  157. // 遮罩层
  158. loading: true,
  159. // 选中数组
  160. ids: [],
  161. // 非单个禁用
  162. single: true,
  163. // 非多个禁用
  164. multiple: true,
  165. // 显示搜索条件
  166. showSearch: true,
  167. // 总条数
  168. total: 0,
  169. // 传感器表格数据
  170. sensorList: [],
  171. // 弹出层标题
  172. title: "",
  173. // 是否显示弹出层
  174. open: false,
  175. // 部门树选项
  176. deptOptions: [],
  177. subjectOptions: [],
  178. subjectAddOptions: [],
  179. sensorAddOptions: [],
  180. // 查询参数
  181. queryParams: {
  182. pageNum: 1,
  183. pageSize:20,
  184. name: null,
  185. factory: null,
  186. type: [],
  187. senseData: null,
  188. gatewayId: null,
  189. dataUpper: null,
  190. senseState: null,
  191. dataLower: null,
  192. macAdd: null,
  193. subjectId: null,
  194. deptId: null,
  195. deptName: null,
  196. userId: null,
  197. },
  198. // 表单参数
  199. form: {},
  200. // 表单校验
  201. rules: {
  202. name:[
  203. {required: true, message: '传感器名称不能为空', trigger: 'blur'},
  204. { required: true, message: "传感器名称不能为空", validator: this.spaceJudgment, trigger: "blur" }
  205. ],
  206. type:[
  207. {required: true, message: '传感器类型不能为空', trigger: 'blur'},
  208. { required: true, message: "传感器类型不能为空", validator: this.spaceJudgment, trigger: "blur" }
  209. ],
  210. gatewayId:[
  211. {required: true, message: '网关不能为空', trigger: 'blur'},
  212. { required: true, message: "网关不能为空", validator: this.spaceJudgment, trigger: "blur" },
  213. { pattern:/^(192\.168(\.(\d|([1-9]\d)|(1\d{2})|(2[0-4]\d)|(25[0-5]))){2})$/, message: "请输入正确的网关", trigger: "blur" }
  214. ],
  215. senseData:[
  216. {required: true, message: '检测数据不能为空', trigger: 'blur'},
  217. { required: true, message: "检测数据不能为空", validator: this.spaceJudgment, trigger: "blur" }
  218. ],
  219. dataUpper:[
  220. {required: true, message: '数据上限不能为空', trigger: 'blur'},
  221. { required: true, message: "数据上限不能为空", validator: this.spaceJudgment, trigger: "blur" }
  222. ],
  223. dataLower:[
  224. {required: true, message: '数据下限不能为空', trigger: 'blur'},
  225. { required: true, message: "数据下限不能为空", validator: this.spaceJudgment, trigger: "blur" }
  226. ],
  227. subjectId:[
  228. {required: true, message: '实验室不能为空', trigger: 'blur'}
  229. ]
  230. },
  231. //MQTT请求参数-设备
  232. msg:"",
  233. };
  234. },
  235. created() {
  236. },
  237. mounted(){
  238. this.getList();
  239. this.getDeptList();
  240. },
  241. methods: {
  242. /** 查询实验室字典列表 */
  243. getSubjectDictList (deptId) {
  244. this.subjectOptions = null;
  245. this.loading = true;
  246. // this.queryParams.deptId = deptId;
  247. let params = {};
  248. params.deptId = deptId;
  249. this.queryParams.subjectId = "";
  250. subjectDictList(params).then(response => {
  251. this.subjectOptions = response.data;
  252. this.loading = false;
  253. });
  254. },
  255. /** 查询实验室字典列表 */
  256. getSubjectAddDictList () {
  257. this.subjectAddOptions = null;
  258. this.loading = true;
  259. let params = {};
  260. subjectDictList(params).then(response => {
  261. this.subjectAddOptions = response.data;
  262. this.loading = false;
  263. });
  264. getSensorList().then(response => {
  265. this.sensorAddOptions = response.data;
  266. });
  267. },
  268. /** 查询传感器列表 */
  269. getList() {
  270. this.loading = true;
  271. listSensor(this.queryParams).then(response => {
  272. this.sensorList = response.rows;
  273. this.total = response.total;
  274. this.loading = false;
  275. });
  276. },
  277. /** 查询学院列表 */
  278. getDeptList() {
  279. listDepartments().then(response => {
  280. this.$set(this, 'deptOptions', response.data)
  281. });
  282. },
  283. // 筛选节点
  284. filterNode(value, data) {
  285. if (!value) return true;
  286. return data.label.indexOf(value) !== -1;
  287. },
  288. // 节点单击事件
  289. handleNodeClick(data) {
  290. this.queryParams.deptId = data;
  291. // console.log("data",data);
  292. this.getSubjectDictList(data);
  293. // this.getList();
  294. },
  295. // 取消按钮
  296. cancel() {
  297. this.open = false;
  298. this.reset();
  299. },
  300. // 表单重置
  301. reset() {
  302. this.form = {
  303. id: null,
  304. name: null,
  305. factory: null,
  306. type: null,
  307. senseData: null,
  308. gatewayId: null,
  309. dataUpper: null,
  310. dataLower: null,
  311. macAdd: null,
  312. subjectId: null,
  313. deptId: null,
  314. createTime: null,
  315. deptName: null,
  316. userId: null,
  317. createBy: null,
  318. updateTime: null,
  319. updateBy: null,
  320. remark: null,
  321. configName:null,
  322. configStatus:null
  323. };
  324. this.resetForm("form");
  325. },
  326. /** 搜索按钮操作 */
  327. handleQuery() {
  328. this.queryParams.pageNum = 1;
  329. this.getList();
  330. },
  331. /** 重置按钮操作 */
  332. resetQuery() {
  333. this.subjectOptions = [];
  334. this.resetForm("queryForm");
  335. this.handleQuery();
  336. },
  337. // 多选框选中数据
  338. handleSelectionChange(selection) {
  339. this.ids = selection.map(item => item.id)
  340. this.single = selection.length!==1
  341. this.multiple = !selection.length
  342. },
  343. /** 新增按钮操作 */
  344. handleAdd() {
  345. this.reset();
  346. this.getSubjectAddDictList();
  347. this.open = true;
  348. this.title = "新增传感器";
  349. },
  350. /** 修改按钮操作 */
  351. handleUpdate(row) {
  352. this.reset();
  353. this.getSubjectAddDictList();
  354. const id = row.id || this.ids
  355. getSensor(id).then(response => {
  356. this.form = response.data;
  357. this.form.type = response.data.type.enumName;
  358. this.open = true;
  359. this.title = "修改传感器";
  360. });
  361. },
  362. /** 提交按钮 */
  363. submitForm() {
  364. this.$refs["form"].validate(valid => {
  365. if (valid) {
  366. if (this.form.id != null) {
  367. this.form.senseState = null
  368. updateSensor(this.form).then(response => {
  369. this.msgSuccess("修改成功");
  370. this.open = false;
  371. this.getList();
  372. });
  373. } else {
  374. addSensor(this.form).then(response => {
  375. this.msgSuccess("新增成功");
  376. this.open = false;
  377. this.getList();
  378. });
  379. }
  380. }
  381. });
  382. },
  383. /** 删除按钮操作 */
  384. handleDelete(row) {
  385. const ids = row.id || this.ids;
  386. this.$confirm('确认删除传感器吗?', "警告", {
  387. confirmButtonText: "确定",
  388. cancelButtonText: "取消",
  389. type: "warning"
  390. }).then(function() {
  391. return delSensor(ids);
  392. }).then(() => {
  393. this.getList();
  394. this.msgSuccess("删除成功");
  395. }).catch(() => {});
  396. },
  397. /** 导出按钮操作 */
  398. handleExport() {
  399. this.download('laboratory/sensor/export', {
  400. ...this.queryParams
  401. }, `laboratory_sensor.xlsx`)
  402. }
  403. },
  404. };
  405. </script>
  406. <style scoped lang="scss">
  407. .sensor{
  408. display: flex!important;
  409. flex-direction: column;
  410. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  411. padding:20px!important;
  412. .button-box{
  413. width:200px;
  414. display: flex;
  415. }
  416. .form-box{
  417. }
  418. }
  419. </style>