smartVentilation.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <!--硬件管理/智能通风-->
  2. <template>
  3. <div class="smartVentilation">
  4. <el-table v-loading="loading" border :data="hardwareList" @selection-change="handleSelectionChange">
  5. <el-table-column label="名称" align="left" prop="name" />
  6. <el-table-column label="学院" align="left" prop="deptName" />
  7. <el-table-column label="实验室" align="left" prop="subjectName" />
  8. <el-table-column label="继电器编号" align="left" prop="relayCode" />
  9. <el-table-column label="状态" align="left" >
  10. <template slot-scope="scope">
  11. <p :class="scope.row.status==4?'table-type-color-ash':(scope.row.status==3?'table-type-color-green':(scope.row.status==0?'table-type-color-red':''))">{{scope.row.status==4?'关闭':(scope.row.status==3?'开启':(scope.row.status==0?'离线':(!scope.row.status?'未知':'')))}}</p>
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="开关" align="left" >
  15. <template slot-scope="scope" class="captcha-img">
  16. <el-switch
  17. v-if="scope.row.status == 3||scope.row.status == 4"
  18. @click.native="changeIsNeedCaptcha(scope.row)"
  19. class="switch captcha-img"
  20. :active-value="3"
  21. :inactive-value="4"
  22. v-model="scope.row.status"
  23. active-text="开"
  24. inactive-text="关"
  25. disabled
  26. >
  27. </el-switch>
  28. <p v-else :class="scope.row.status==0?'table-type-color-red':''">{{scope.row.status==0?'离线':'未知'}}</p>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
  32. <template slot-scope="scope">
  33. <div class="button-box">
  34. <el-dropdown @command="moreClick">
  35. <p class="table-min-button">更多>></p>
  36. <el-dropdown-menu slot="dropdown">
  37. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;" :command="{row:scope.row,command:1}"
  38. v-hasPermiAnd="['laboratory:hardware:query','laboratory:hardware:edit']">修改设备</el-dropdown-item>
  39. <el-dropdown-item style="margin:0 10px;" :command="{row:scope.row,command:2}"
  40. v-hasPermi="['laboratory:hardware:remove']">删除设备</el-dropdown-item>
  41. </el-dropdown-menu>
  42. </el-dropdown>
  43. </div>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. <pagination :page-sizes="[20, 30, 40, 50]"
  48. v-show="total>0"
  49. :total="total"
  50. layout="total, prev, pager, next, sizes, jumper"
  51. :page.sync="queryParams.pageNum"
  52. :limit.sync="queryParams.pageSize"
  53. @pagination="getList"
  54. />
  55. <!-- 添加或修改硬件对话框 -->
  56. <el-drawer
  57. class="videoSurveillance-drawer"
  58. :visible.sync="drawer"
  59. direction="rtl"
  60. ref="drawer"
  61. :with-header="false"
  62. :show-close="false"
  63. :before-close="handleClose">
  64. <div class="videoSurveillance-drawer-max-box">
  65. <div class="videoSurveillance-drawer-content">
  66. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  67. <el-form-item label="硬件名称" prop="name">
  68. <el-input
  69. v-model="form.name"
  70. placeholder="请输入硬件名称"
  71. clearable
  72. size="small"
  73. maxLength="8"
  74. />
  75. </el-form-item>
  76. <el-form-item label="实验室" prop="subjectId">
  77. <el-select v-model="form.subjectId" placeholder="请选择实验室">
  78. <el-option v-for="lab in labListOptions"
  79. :key="lab.id"
  80. :label="lab.name"
  81. :value="lab.id">
  82. </el-option>
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="继电器类型" label-width="1rem" @change="radioChange">
  86. <el-radio-group v-model="form.hardwareType">
  87. <el-radio :label="item.value" :key="item.value" v-for="item in hardwardTypeList">{{item.label}}</el-radio>
  88. </el-radio-group>
  89. </el-form-item>
  90. <el-form-item label="绑定继电器" prop="relayCode" v-if="form.hardwareType==1">
  91. <el-select v-model="form.relayCode" placeholder="请选择继电器" clearable @change="loadRelayNum" @clear="loadClear">
  92. <el-option v-for="relay in relayList"
  93. :key="relay.code"
  94. :label="relay.code"
  95. :value="relay.code">
  96. </el-option>
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="继电器编号" prop="relayCode" v-if="form.hardwareType==2">
  100. <el-input
  101. v-model="form.relayCode"
  102. placeholder="请输入继电器编号"
  103. clearable
  104. size="small"
  105. maxLength="15"
  106. />
  107. </el-form-item>
  108. <el-form-item label="继电器位置" prop="bit">
  109. <el-select v-model="form.bit" placeholder="请选择继电器位置" clearable>
  110. <el-option v-for="lab in relayNumList"
  111. :key="lab.name"
  112. :label="lab.name"
  113. :value="lab.name">
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item label="配置名称" prop="relayCode" v-if="form.hardwareType==2">
  118. <el-input
  119. v-model="form.configName"
  120. placeholder="请输入配置名称"
  121. clearable
  122. size="small"
  123. maxLength="8"
  124. />
  125. </el-form-item>
  126. <el-form-item label="配置状态" prop="relayCode" v-if="form.hardwareType==2">
  127. <el-input
  128. v-model="form.configStatus"
  129. placeholder="请输入配置状态"
  130. clearable
  131. size="small"
  132. maxLength="8"
  133. />
  134. </el-form-item>
  135. </el-form>
  136. </div>
  137. <div class="videoSurveillance-bottom-button-box">
  138. <p></p>
  139. <p @click="offDrawer">取消</p>
  140. <p @click="submitForm">提交</p>
  141. </div>
  142. </div>
  143. </el-drawer>
  144. </div>
  145. </template>
  146. <script>
  147. import mqtt from 'mqtt'
  148. import { subjectDictList } from "@/api/laboratory/group";
  149. import { listDepartments } from "@/api/system/dept";
  150. import { listHardware, getHardware, delHardware, addHardware, updateHardware,queryHardwareType,getHardwareDetail,getSubjectLayout,hardWareControl } from "@/api/laboratory/hardware";
  151. import { treeselect } from "@/api/system/dept";
  152. import Treeselect from "@riophae/vue-treeselect";
  153. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  154. import { listRelay } from "@/api/laboratory/relay";
  155. export default {
  156. props:{
  157. pageType:{},
  158. queryParams:{}
  159. },
  160. components: { Treeselect },
  161. name: "smartVentilation",
  162. data() {
  163. return {
  164. tableButtonType:this.hasPermiDom(['laboratory:hardware:query','laboratory:hardware:edit','laboratory:hardware:remove']),
  165. index:'',
  166. // 遮罩层
  167. loading: true,
  168. // 选中数组
  169. ids: [],
  170. // 非单个禁用
  171. single: true,
  172. // 非多个禁用
  173. multiple: true,
  174. // 显示搜索条件
  175. showSearch: true,
  176. // 总条数
  177. total: 0,
  178. // 硬件表格数据
  179. hardwareList: [],
  180. // 弹出层标题
  181. title: "",
  182. // 是否显示弹出层
  183. open: false,
  184. // 部门树选项
  185. deptOptions: [],
  186. subjectOptions: [],
  187. isUpdate:false,
  188. switch:0,
  189. disabledType: "",
  190. // 表单参数
  191. form: {
  192. hardwareType: 1,
  193. relayCode:null
  194. },
  195. // 表单校验
  196. rules: {
  197. name: [
  198. { required: true, message: "请输入硬件名称", trigger: "blur" },
  199. { required: true, message: "请输入硬件名称", validator: this.spaceJudgment, trigger: "blur" }
  200. ],
  201. type: [
  202. { required: true, message: "请选择硬件类型", trigger: "blur" }
  203. ],
  204. subjectId:[
  205. { required: true, message: "请选择实验室", trigger: "blur" },
  206. ]
  207. },
  208. hardTypeOptions:{},
  209. labListOptions:{},
  210. // 关联实验室弹窗开关
  211. drawer:false,
  212. mapData:{
  213. widthData:"60",
  214. heightData:"123",
  215. list:[
  216. {
  217. id: "",
  218. top:0,
  219. left:0
  220. }
  221. ]
  222. },
  223. mapList:[],
  224. // 继电器
  225. relayList: [],
  226. relayNumList:[
  227. {name:1},
  228. {name:2},
  229. {name:3},
  230. {name:4},
  231. {name:5},
  232. {name:6},
  233. {name:7},
  234. {name:8},
  235. {name:9},
  236. {name:10},
  237. {name:11},
  238. {name:12}
  239. ],
  240. hardwardTypeList:[
  241. {value:1,label:"老继电器"},
  242. {value:2,label:"新继电器"}
  243. ],
  244. mtopic:"lab/hardware/data",
  245. //mqtt发送id数组
  246. mqttIdList:[],
  247. };
  248. },
  249. created() {
  250. },
  251. mounted(){
  252. this.getList();
  253. this.getDeptList();
  254. },
  255. methods: {
  256. radioChange(){
  257. console.log("************************","触发")
  258. let self = this;
  259. self.relayNumList=[];
  260. let num = 12;
  261. if(this.form.hardwareType==2){
  262. let list = [];
  263. for(let i=0;i<num;i++){
  264. let obj = {
  265. name:i+1
  266. }
  267. list.push(obj);
  268. }
  269. self.relayNumList = list;
  270. }
  271. },
  272. // 开启关闭验证
  273. async changeIsNeedCaptcha (row) {
  274. let self = this;
  275. console.log(row.status)
  276. if(row.status!=3 && row.status!=4){
  277. return
  278. }
  279. let text = row.status==3?'关闭':(row.status==4?'开启':'')
  280. this.$confirm(`是否`+text+`此设备`, "提示", {
  281. confirmButtonText: "确定",
  282. cancelButtonText: "取消",
  283. type: "warning"
  284. }).then(async () => {
  285. self.switchChange(row)
  286. }).catch(() => {
  287. })
  288. },
  289. //开关按钮
  290. switchChange(row){
  291. let switchData = {
  292. id:row.id,
  293. switchVal:row.status==3?'close':(row.status==4?'open':'')
  294. };
  295. hardWareControl(switchData).then(response => {
  296. console.log(response.data);
  297. if(response.code==200){
  298. row.status = row.status==3?4:(row.status==4?3:'')
  299. }
  300. });
  301. },
  302. //删除
  303. delBox(item){
  304. console.log(item)
  305. },
  306. moveClick(index){
  307. this.moveIndex = index
  308. console.log(",index",index)
  309. },
  310. //锚点拖动
  311. move(e){
  312. let odiv = e.target; //获取目标元素
  313. //算出鼠标相对元素的位置
  314. let disX = e.clientX - odiv.offsetLeft;
  315. let disY = e.clientY - odiv.offsetTop;
  316. document.onmousemove = (e)=>{ //鼠标按下并移动的事件
  317. //用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
  318. let left = e.clientX - disX;
  319. let top = e.clientY - disY;
  320. //绑定元素位置到positionX和positionY上面
  321. //移动当前元素
  322. if(left>0&&left<(this.mapData.widthData*3-60)){
  323. odiv.style.left = left + 'px';
  324. this.mapData.list[this.moveIndex].left = left;
  325. this.mapData.list[this.moveIndex].minLeft = parseInt(left/6);
  326. }
  327. if(top>0&&top<(this.mapData.heightData*3-60)){
  328. odiv.style.top = top + 'px';
  329. this.mapData.list[this.moveIndex].top = top;
  330. this.mapData.list[this.moveIndex].minTop = parseInt(top/6);
  331. }
  332. };
  333. document.onmouseup = (e) => {
  334. document.onmousemove = null;
  335. document.onmouseup = null;
  336. };
  337. },
  338. getHardTypeList(){
  339. queryHardwareType().then(response => {
  340. if(response.code==200){
  341. this.hardTypeOptions=response.data;
  342. }
  343. console.log(this.hardTypeOptions)
  344. });
  345. },
  346. //关联实验室弹窗
  347. drawerBoxOnTwo(){
  348. this.drawerTwo = true;
  349. },
  350. //关联实验室弹窗
  351. drawerBoxOn(){
  352. this.drawer = true;
  353. },
  354. //关闭弹窗
  355. offDrawer(){
  356. this.$refs.drawer.closeDrawer();
  357. },
  358. //弹窗关闭前回调
  359. handleClose(done) {
  360. this.$confirm('确认关闭?')
  361. .then(_ => {
  362. done();
  363. })
  364. .catch(_ => {});
  365. },
  366. //更多选项
  367. moreClick(item){
  368. if(item.command == 1){
  369. this.handleUpdate(item.row)
  370. }else if(item.command == 2){
  371. this.handleDelete(item.row)
  372. }
  373. },
  374. /** 查询硬件列表 */
  375. getList() {
  376. this.offMQTT();
  377. this.loading = true;
  378. this.queryParams.type = this.pageType;
  379. listHardware(this.queryParams).then(response => {
  380. this.hardwareList = response.rows;
  381. this.total = response.total;
  382. this.loading = false;
  383. //处理实验室id
  384. let list = [];
  385. for(let i=0;i<response.rows.length;i++){
  386. let num = 0;
  387. for(let o=0;o<list.length;o++){
  388. if(response.rows[i].subjectId == list){
  389. num++
  390. }
  391. }
  392. if(num == 0){
  393. list.push(response.rows[i].subjectId)
  394. }
  395. }
  396. this.$set(this,'mqttIdList',list);
  397. this.subscriptionMQTT();
  398. });
  399. },
  400. //MQTT订阅
  401. subscriptionMQTT(){
  402. let self = this;
  403. this.client = mqtt.connect(process.env.VUE_APP_BASE_MQTT_API, {
  404. username: process.env.VUE_APP_BASE_MQTT_USERNAME,
  405. password: process.env.VUE_APP_BASE_MQTT_PASSWORD
  406. });
  407. this.client.on("connect", e =>{
  408. console.log("连接成功");
  409. for(let i=0;i<self.mqttIdList.length;i++){
  410. this.client.subscribe(this.mtopic+self.mqttIdList[i], (err) => {
  411. if (!err) {
  412. console.log("订阅成功:" + this.mtopic+self.mqttIdList[i]);
  413. }
  414. });
  415. }
  416. });
  417. this.client.on("message", (topic, message) => {
  418. if (message){
  419. let data = JSON.parse(message)
  420. // this.getStatistics();
  421. for(let i=0;i<data.data.length;i++){
  422. for(let o=0;o<self.hardwareList.length;o++){
  423. if(data.data[i].num == self.hardwareList[o].id){
  424. if (data.data[i].hardwareOperate == 'CLOSE') {
  425. self.$set(self.hardwareList[o],'status',4);
  426. } else if (data.data[i].hardwareOperate == 'OPEN') {
  427. self.$set(self.hardwareList[o],'status',3);
  428. } else if (data.data[i].hardwareOperate == 'OFFLINE') {
  429. self.$set(self.hardwareList[o],'status',0);
  430. }
  431. }
  432. }
  433. }
  434. }
  435. });
  436. },
  437. // 查询继电器列表
  438. getRelayList(){
  439. listRelay().then(response => {
  440. this.relayList = response.data;
  441. if(this.form.relayCode){
  442. let self = this
  443. let num = ""
  444. for(let i=0;i<self.relayList.length;i++){
  445. if(self.relayList[i].code == this.form.relayCode){
  446. num = self.relayList[i].routeNum
  447. }
  448. }
  449. let list = [];
  450. for(let i=0;i<num;i++){
  451. let obj = {
  452. name:i+1
  453. }
  454. list.push(obj);
  455. }
  456. this.relayNumList = list;
  457. }
  458. });
  459. },
  460. // 取消按钮
  461. cancel() {
  462. this.open = false;
  463. this.reset();
  464. },
  465. //清空按钮
  466. loadClear(){
  467. this.form.bit = '';
  468. },
  469. loadRelayNum(e){
  470. let self = this;
  471. let num = ""
  472. for(let i=0;i<self.relayList.length;i++){
  473. if(self.relayList[i].code == e){
  474. num = self.relayList[i].routeNum
  475. }
  476. }
  477. let list = [];
  478. for(let i=0;i<num;i++){
  479. let obj = {
  480. name:i+1
  481. }
  482. list.push(obj);
  483. }
  484. this.relayNumList = list;
  485. },
  486. loadHardware(){
  487. let self = this;
  488. this.mapList = [];
  489. let newId = this.mapData.list[0].id;
  490. // this.mapData.list = [];
  491. let queryParam = {};
  492. if(this.form.id){
  493. queryParam.id = this.form.id;
  494. }else{
  495. queryParam.id = -1;
  496. }
  497. queryParam.subjectId = this.form.subjectId;
  498. getHardwareDetail(queryParam).then(response => {
  499. let subHardList = response.data.subjectHardPosiList;
  500. for(var i=0;i<subHardList.length;i++){
  501. if(response.data.subjectHardPosiList[i].id!=newId){
  502. this.mapList.push({"name":response.data.subjectHardPosiList[i].hardName,"y":(response.data.subjectHardPosiList[i].horizontalAxis/3).toFixed(0),"x":(response.data.subjectHardPosiList[i].verticalAxis/3).toFixed(0)});
  503. }
  504. }
  505. this.$forceUpdate();
  506. });
  507. getSubjectLayout(this.form.subjectId).then(response => {
  508. if(response.data){
  509. this.mapData.widthData = response.data.layWidth;
  510. this.mapData.heightData = response.data.layHeight;
  511. }else{
  512. this.mapData.widthData = 60;
  513. this.mapData.heightData = 123;
  514. }
  515. this.$forceUpdate();
  516. });
  517. let obj = JSON.parse(JSON.stringify(this.mapData.list[0]));
  518. obj.x = 0;
  519. obj.y = 0;
  520. obj.top = 0;
  521. obj.left = 0;
  522. this.mapData.list.splice(0,1);
  523. setTimeout(function(){
  524. self.mapData.list.push(obj);
  525. },50);
  526. this.$forceUpdate()
  527. },
  528. /** 查询实验室字典列表 */
  529. getSubjectDictList (deptId) {
  530. this.subjectOptions = null;
  531. this.loading = true;
  532. // this.queryParams.deptId = deptId;
  533. let params = {};
  534. params.deptId = deptId;
  535. this.queryParams.subjectId = "";
  536. subjectDictList(params).then(response => {
  537. this.subjectOptions = response.data;
  538. this.loading = false;
  539. });
  540. },
  541. /** 查询学院列表 */
  542. getDeptList() {
  543. listDepartments().then(response => {
  544. this.$set(this, 'deptOptions', response.data)
  545. });
  546. },
  547. // 筛选节点
  548. filterNode(value, data) {
  549. if (!value) return true;
  550. return data.label.indexOf(value) !== -1;
  551. },
  552. // 节点单击事件
  553. handleNodeClick(data) {
  554. this.queryParams.deptId = data;
  555. // console.log("data",data);
  556. this.getSubjectDictList(data);
  557. // this.getList();
  558. },
  559. // 表单重置
  560. reset() {
  561. this.form = {
  562. id: null,
  563. name: null,
  564. factory: null,
  565. type: null,
  566. macAdd: null,
  567. subjectId: null,
  568. deptId: null,
  569. deptName: null,
  570. operate: 0,
  571. createTime: null,
  572. userId: null,
  573. createBy: null,
  574. updateTime: null,
  575. updateBy: null,
  576. remark: null
  577. };
  578. this.resetForm("form");
  579. },
  580. /** 搜索按钮操作 */
  581. handleQuery() {
  582. this.queryParams.pageNum = 1;
  583. this.getList();
  584. },
  585. /** 重置按钮操作 */
  586. resetQuery() {
  587. this.resetForm("queryForm");
  588. this.handleQuery();
  589. },
  590. // 多选框选中数据
  591. handleSelectionChange(selection) {
  592. this.ids = selection.map(item => item.id)
  593. this.single = selection.length!==1
  594. this.multiple = !selection.length
  595. },
  596. /** 新增按钮操作 */
  597. handleAdd() {
  598. this.reset();
  599. // this.mapList = []
  600. this.$set(this,'mapList',[]);
  601. // this.mapData.list = [{
  602. // id: "",
  603. // top:0,
  604. // left:0
  605. // }];
  606. this.$set(this.mapData,'list',[{id: "", top:0, left:0}]);
  607. this.isUpdate=true;
  608. // this.form.hardwareType=1;
  609. this.$set(this.form,'hardwareType',1);
  610. // this.form.type=this.pageType;
  611. this.$set(this.form,'type',this.pageType);
  612. this.drawer = true;
  613. this.title = "添加硬件";
  614. this.getHardTypeList();
  615. this.getLabList();
  616. this.getRelayList();
  617. // this.reset();
  618. // this.open = true;
  619. // this.title = "添加硬件";
  620. // this.getLabList();
  621. // this.form.type=this.pageType;
  622. },
  623. /** 修改按钮操作 */
  624. handleUpdate(row) {
  625. this.reset();
  626. this.mapList = [];
  627. this.mapData.list = [];
  628. this.isUpdate=true;
  629. this.form.type=this.pageType;
  630. this.getHardTypeList();
  631. this.getLabList();
  632. const id = row.id || this.ids
  633. let queryParam = {};
  634. queryParam.id = id;
  635. queryParam.subjectId = row.subjectId;
  636. getHardwareDetail(queryParam).then(response => {
  637. this.form = response.data;
  638. this.$forceUpdate;
  639. this.getRelayList()
  640. this.title = "修改硬件";
  641. this.drawer = true;
  642. });
  643. },
  644. getLabList(){
  645. subjectDictList().then(response => {
  646. console.log(response)
  647. if(response.code==200){
  648. this.labListOptions=response.data;
  649. }
  650. console.log(this.labListOptions)
  651. });
  652. },
  653. /** 提交按钮 */
  654. submitForm() {
  655. this.form.hardwarePosition={
  656. horizontalAxis:'',
  657. verticalAxis:''
  658. }
  659. this.form.type=this.pageType;
  660. // this.form.hardwarePosition.horizontalAxis=this.mapData.list[0].top;
  661. // this.form.hardwarePosition.verticalAxis=this.mapData.list[0].left;
  662. this.$refs["form"].validate(valid => {
  663. if (valid) {
  664. if (this.form.id != null) {
  665. updateHardware(this.form).then(response => {
  666. this.msgSuccess("修改成功");
  667. this.drawer = false;
  668. this.getList();
  669. });
  670. } else {
  671. addHardware(this.form).then(response => {
  672. this.msgSuccess("新增成功");
  673. this.drawer = false;
  674. this.getList();
  675. });
  676. }
  677. }
  678. });
  679. // this.$refs["form"].validate(valid => {
  680. // if (valid) {
  681. // if (this.form.id != null) {
  682. // updateHardware(this.form).then(response => {
  683. // this.msgSuccess("修改成功");
  684. // this.open = false;
  685. // this.getList();
  686. // });
  687. // } else {
  688. // addHardware(this.form).then(response => {
  689. // this.msgSuccess("新增成功");
  690. // this.open = false;
  691. // this.getList();
  692. // });
  693. // }
  694. // }
  695. // });
  696. },
  697. /** 删除按钮操作 */
  698. handleDelete(row) {
  699. const ids = row.id || this.ids;
  700. this.$confirm('是否确认删除硬件?', "警告", {
  701. confirmButtonText: "确定",
  702. cancelButtonText: "取消",
  703. type: "warning"
  704. }).then(function() {
  705. return delHardware(ids);
  706. }).then(() => {
  707. this.getList();
  708. this.msgSuccess("删除成功");
  709. }).catch(() => {});
  710. },
  711. /** 导出按钮操作 */
  712. handleExport() {
  713. this.download('laboratory/hardware/export', {
  714. ...this.queryParams
  715. }, `laboratory_hardware.xlsx`)
  716. },
  717. //取消订阅关闭MQTT连接
  718. offMQTT(){
  719. let self = this;
  720. if (self.mqttIdList[0]) {
  721. for (let i = 0; i < self.mqttIdList.length; i++) {
  722. self.client.unsubscribe(this.mtopic + self.mqttIdList[i], error => {
  723. if (error) {
  724. console.log('Unsubscribe error', error)
  725. }
  726. })
  727. }
  728. self.client.end();
  729. self.client = {};
  730. }
  731. },
  732. },
  733. beforeDestroy() {
  734. //清除定时器
  735. let self = this;
  736. self.offMQTT();
  737. console.log("beforeDestroy");
  738. },
  739. };
  740. </script>
  741. <style scoped lang="scss">
  742. .smartVentilation{
  743. flex: 1;
  744. display: flex!important;
  745. flex-direction: column;
  746. padding:20px!important;
  747. overflow: hidden;
  748. .form-box{
  749. }
  750. .button-box{
  751. width:350px;
  752. display: flex;
  753. }
  754. }
  755. </style>